locked
Add Enterprise resource to project team using JSOM in Project Server 2013 RRS feed

  • Question

  • I am using Project Online 2013 and want to add Enterprise resource to project team of a respective project by JSOM or REST .



    Amey Pusalkar

    Friday, November 4, 2016 9:19 AM

Answers

  • JSOM

    var resources = projContext.loadQuery(projContext.get_enterpriseResources());
    //executeQueryAsync
    
    //You get an array with enterpries resources, simply filter out the one you neede and send in to the function below.
    
    var draftProject = project.checkOut();
    var r = resources[4];
    draftProject.get_projectResources().addEnterpriseResource(r);
    var updateJob = draftProject.update();
    //And then projContext.executeQueryAsync

    REST

    Send a POST to:

    /_api/ProjectServer/Projects(guid'00000000-0000-0000-0000-000000000000')/Draft/ProjectResources/AddEnterpriseResourceById('00000000-0000-0000-0000-000000000000')

    No body needed.

    EDIT:

    They both have their strengths and weaknesses, sadly they don't complement each other...

    With JSOM you can add multiple resources in a batch query which is very nice.

    BUT since you need an enterprise resource object (not simply a GUID) and due to the limitations of JSOM you are required to fetch the WHOLE enterprise resource pool regardless of how many you actually want to use. There is no way you can filter server side (not the case in CSOM, it's very easy to filter with C# and LINQ). That is a problem if the pool is large which can result in long loading times just to get the pool.

    In that regard the REST method is superior since you only need the resource GUID which you can easily filter with a REST query.

    BUT you can't add resources in a batch, you need a POST for every single resource which can take a very long time if you have a bunch.

    If anyone has any nice tricks or solutions to the limitations above I would very much appreciate them (I'm working with this very thing and the limitations are very annoying...)




    Tuesday, November 8, 2016 9:02 AM

All replies

  • JSOM

    var resources = projContext.loadQuery(projContext.get_enterpriseResources());
    //executeQueryAsync
    
    //You get an array with enterpries resources, simply filter out the one you neede and send in to the function below.
    
    var draftProject = project.checkOut();
    var r = resources[4];
    draftProject.get_projectResources().addEnterpriseResource(r);
    var updateJob = draftProject.update();
    //And then projContext.executeQueryAsync

    REST

    Send a POST to:

    /_api/ProjectServer/Projects(guid'00000000-0000-0000-0000-000000000000')/Draft/ProjectResources/AddEnterpriseResourceById('00000000-0000-0000-0000-000000000000')

    No body needed.

    EDIT:

    They both have their strengths and weaknesses, sadly they don't complement each other...

    With JSOM you can add multiple resources in a batch query which is very nice.

    BUT since you need an enterprise resource object (not simply a GUID) and due to the limitations of JSOM you are required to fetch the WHOLE enterprise resource pool regardless of how many you actually want to use. There is no way you can filter server side (not the case in CSOM, it's very easy to filter with C# and LINQ). That is a problem if the pool is large which can result in long loading times just to get the pool.

    In that regard the REST method is superior since you only need the resource GUID which you can easily filter with a REST query.

    BUT you can't add resources in a batch, you need a POST for every single resource which can take a very long time if you have a bunch.

    If anyone has any nice tricks or solutions to the limitations above I would very much appreciate them (I'm working with this very thing and the limitations are very annoying...)




    Tuesday, November 8, 2016 9:02 AM
  • Hi Henrik ,

    Thanks for your valuable support.

    Need one more help can you tell me how to delete a resource from build team ?



    Amey Pusalkar

    Thursday, January 5, 2017 6:33 AM