5

I am using a workflow to create a project in project server 2013. This seems like a fairly common operation, but I need to set a few pieces of information when I create the project that are not available in the constructor.

Process Outline

for my own purposes I am using Chrome app DHC for creating these requests.

I use headers:

  Accept:       application/json;odata=verbose
  Content-Type: application/json;odata=verbose
  1. get the Context (X-RequestDigest):

    dev1projects/PWA/_api/contextinfo 
    [POST empty body]
    
  2. Pick a Project:

    dev1projects/PWA/_api/ProjectServer/Projects?$Top=1
    [GET]
    
  3. Check out the project:

    dev1projects/PWA/_api/ProjectServer/Projects('theguidi-just-pick-from-theprojectabove')/checkOut()
    //Add Header X-RequestDigest:0xTheStringFromTheContextQuery(d/GetContextWebInformation/FormDigestValue)
    [POST empty body]
    
  4. Update the Draft item:

    dev1projects/PWA/_api/ProjectServer/Projects('projectid')/Draft/update()
    //Add Header X-RequestDigest:0xTheStringFromTheContextQuery(d/GetContextWebInformation/FormDigestValue)
    [POST]
    {"__metadata":{"type":"PS.DraftProject"},"Name":"Test 679"}
    
  5. Check In the Draft:

    dev1projects/PWA/_api/ProjectServer/Projects('theguidi-just-pick-from-theprojectabove')/Draft/checkIn()
    //Add Header X-RequestDigest:0xTheStringFromTheContextQuery(d/GetContextWebInformation/FormDigestValue)
    [POST empty body]
    

For step 4 I have seen a couple of examples that I have not been able to replicate success with. So I am coming to you for help.

Chris Givens Solution for updating owner made an entry in this question about how to accomplish an update tot he owner, but I have not been able to replicate his solution.

I need to update enterprise custom fields as well, so if you could please look for a solution to either updating a field like owner, or enterprise custom fields I would appreciate it.

In addition, I am working with Infopath and sharepoint designer workflow. So far my project is codeless and if possible I would like it to remain that way so I do not need admin deployment or approval.

UPDATE:

After some digging it turns out that the /draft/Update() is creating a queue job visible in the Central Admin Queue Jobs. I successfully changed Something in the Project using method 1 in step 4. I just need to hammer out the syntax for a successful update...

UPDATE:

Ok, I can repeatedly change the name field. Woot for progress. See my code in step 4. Now, I need to find a way to use this process to update the Finish date and several enterprise custom fields...

UPDATE:

Major breakthrough!

So I was browsing the SDK and found that the workflow web services for project server have a few interesting entries...

dev1projects/PWA/_api/ProjectServer/WorkflowActivities/CreateProjectFromListItem
[POST]
body:
{"webId":"78c039d0-f64e-493b-bf81-e5c857578c54",
"listId":"138936e6-753b-4143-8be3-37bdbb0957ea",
"itemId":"2",
"eptId":"09fa52b4-059b-4527-926e-99f9be96437a"}

it is late, and I need to go home, but please be aware that these guids will not work for you :->

So, that allows me to create a project from a list item. d/result (i think) has a project guid in it.

Then, I can use:

dev1projects/PWA/_api/ProjectServer/WorkflowActivities/updateTextProperty
[POST]
{"projectId":"03a2693e-d949-e411-940e-00155d017536",
"propertyId":"91266190-7d3f-e411-940d-00155d017536",
"value":"This is gonna be great"}

to store a value in the project's enterprise custom field.

I do not really want to make a web service call to populate each field on this project, but after nearly giving up I think there might be a path to success...

I would happily give my reputation points to someone who can clean this up into a clean solution. Bonus points for finding a solution to updating multiple fields with a single httprequest...

UPDATE:

The list item that you use to create the project from only passes in the title, so you are on your own for required fields. Also, it looks like the list needs to be in the same site collection with PWA.

2
  • Any luck on updating custom project lookup fields? Be very interested to know :-)
    – user42810
    May 29 '15 at 4:50
  • I wound up pushing that piece to the v2. So I only have theory on this. I think you can update the value of the custom field with the ID number of the list option you wish to set. I would try the updateNumberProperty action first. Then I would try the updateGuidProperty action second (using guid of the selected item instead of ID). Please note that I have not done POC, so I am not certain, but that is where I would start.
    – ghangas
    May 29 '15 at 16:48
1

Robert (6 years later lol),

I was able to leverage your discoveries into a working update from my Dynamics instance to Project Online using Power Automate. Some notable things I found were:

  • Custom fields require their own call -- I couldn't feed an array of objects to the UpdateTextProperty call. That was rejected.

  • A 2 second delay between subsequent calls to update custom fields was needed to avoid write-lock from SharePoint. I will try to trim this to the minimum, but for testing 2 seconds was okay for my proof-of-concept.

  • A check-out and check-in/publish were required AFTER the calls to update custom fields (after another 2 sec delay) in order to see the results immediately in Project Online after the flow runs.

  • Lookup fields were no different from updating a text field -- just ensure that the value that you pass as a value (I used a text type) matches the corresponding value from the look-up table.

  • If you want to update default fields in the same flow, you simply use a PATCH call in-between the Check-out and Check-in actions.

I want to thank you for your documentation and ingenuity here. Without your work, I surely would still be scratching my head and trying other things out.

5
  • Thank you for your effort and findings! I have repeatedly regretted not having found or taken the opportunity to dig in to the questions I left unanswered. By any chance, do you have some example code you could add to your answer to help the next dev to come along? Again, nice work!
    – ghangas
    Sep 7 at 22:06
  • 1
    My update calls for the custom fields are just like the ones outlined above. Here is the URL and Payload for the PATCH calls. Remember, you have to update in the following sequence -- update Custom Fields (one at a time) with API calls, check out the Project, update Default fields, check in the project. Checking out / in of the Project is critical to your changes being displayed immediately after your update runs.
    – Jesse Lott
    Sep 8 at 12:07
  • 1
    URL for Default fields: ProjectOnlineURL/_api/ProjectServer/Projects(<ProjectID'>)/Draft
    – Jesse Lott
    Sep 8 at 12:13
  • 1
    Payload: {"Description": "⁠Business Need⁠","Name":"⁠Project Name"}
    – Jesse Lott
    Sep 8 at 12:14
  • 1
    Accept: application/json;odata=nometadata Content-Type: application/json;odata=nometadata IF-MATCH: *
    – Jesse Lott
    Sep 8 at 12:25
4

OK folks, Here is the answer for how to codelessly update a project from outside PWA when you need to update enterprise custom fields.

Get the property GUID

dev1projects/PWA/_api/ProjectServer/Projects('theguidi-just-pick-from-theprojectabove')/CustomFields [GET]

retrieve d/results/(the index of the field you want to update)/Id

Update the Field

dev1projects/PWA/_api/ProjectServer/WorkflowActivities/updateTextProperty [POST]

{"projectId":"f1e76bad-014a-e411-940e-00155d017536",
"propertyId":"91266190-7d3f-e411-940d-00155d017536",
"value":"This is gonna be really great"}

To update something other than a text field test drive these URLs that I grabbed straight from the SDK:

updateBooleanProperty
updateCurrencyProperty
updateDateTimeProperty
updateGuidProperty
updateIdeaListItemStatus
updateIntegerProperty
updateNumberProperty
updateProjectStageStatus
updateTextProperty

What if I need to update a lookup field? I don't know yet. But I will know by the end of next week. In the meantime, thanks for reading, and I hope you find this useful...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.