cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
illmatic
Helper IV
Helper IV

Use SharePoint Rest API to update Project Details in PWA

I'm trying to update a field in the Project Details of a project by a flow. Should I be using SharePoint REST API or HTTP web action?  I'm currently attempting with the SP API action, and have the following entries on the action:

spaction.png

This renders a 'forbidden' value for an error.   What is the best way to dynamically set fields at the Project level for PWA?

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User II
Super User II

Hi @illmatic,

 

As far as I am aware the ProjectData endpoint is for reporting purposes. Try the ProjectServer endpoint instead.

 

Below is an example of the request with the project description (one of the default fields in the project details).

 

I believe that with custom fields you have to approach it a bit differently, so you might want to adjust this example:

https://docs.microsoft.com/en-us/office/client-developer/project/bulk-update-custom-fields-and-creat...

 

 

updateprojectdescription.png

 

Btw, don't forget to checkout, update, checkin and publish your project 😄

projectonline_steps.png

 

View solution in original post

14 REPLIES 14
Expiscornovus
Super User II
Super User II

Hi @illmatic,

 

As far as I am aware the ProjectData endpoint is for reporting purposes. Try the ProjectServer endpoint instead.

 

Below is an example of the request with the project description (one of the default fields in the project details).

 

I believe that with custom fields you have to approach it a bit differently, so you might want to adjust this example:

https://docs.microsoft.com/en-us/office/client-developer/project/bulk-update-custom-fields-and-creat...

 

 

updateprojectdescription.png

 

Btw, don't forget to checkout, update, checkin and publish your project 😄

projectonline_steps.png

 

View solution in original post

illmatic
Helper IV
Helper IV

Thanks! @Expiscornovus 

I tried this approach but received the following error:

An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.


Assuming this has to do with the Body parameter?  

Expiscornovus
Super User II
Super User II

Hi @illmatic,

 

I don't think it is because of the body parameter. I have checked my Project Online environment and I am not seeing any ProjectManagerName field on the Project details page. So, I am assuming you created it as a custom field. Is it is single line of text custom field?

 

When you are using a custom field the approach would be slightly different, this would be the draft/updatecustomfields method. In my previous example I was using a standard field (description).

 

Below is an example of how you could update a custom field of single line of text.

You have to use the internalname of the ProjectManagerName custom field for the key. Paul Mather has written a good blog about how to find that internalname:

https://pwmather.wordpress.com/2018/05/21/using-rest-in-javascript-to-update-projectonline-project-c...

 

{"customFieldDictionary":[{"Key":"@{variables('InternalName')}",
"Value":"John Doe", "ValueType":"Edm.String"}]}

 

customfield_projectdetails.png

illmatic
Helper IV
Helper IV

@Expiscornovus 

 

Thanks but it is not a custom field that I created nor is it present in the Enterprise Custom Fields that are created by the system by default.  It is part of the Project entity.  It isn't visible in the Project Details page at all.  I was able to locate it using SPInsider plugin.  

 

And sorry, this is my mistake... I kind of changed requirement based on when I first started creating the post.

UPDATE:  I am realizing that this initial field 'ProjectManagerName' was a field I could see in the ProjectData feed, but I do not see it listed in ProjectServer.   Is there an equivalent field for this?  Where would this information be derived from?   As again, it's not a custom field.  Essentially, my understanding [and I may be wrong] is that listing a Project Manager may drive PWA permissions/SP groups.  I would like to set a Project Manager so that person is automatically given Owner rights when their site is created by PWA.     

illmatic
Helper IV
Helper IV

I have attempted to update a field that is listed on the Project Details page.  Both 'Description' and 'Owner' still yield the same error with Patch method.  I have modified the Action to use a Post method and this action just times out.  I'm unsure of the cause.

Expiscornovus
Super User II
Super User II

Hi @illmatic,

 

Lets start with that Description test, just want to make sure that you can at least update default project details fields.

 

Can you post a screenshot of the configuration of the send an http request action or the whole flow setup?

 

And second question about that test. You are checking the project out in your flow before you are send the PATCH request? 

illmatic
Helper IV
Helper IV

Yep!  I tried Description and I either get a BadRequest or it hangs forever.   I can verify that yes I am checking out the project prior to running the action.  Here is an overview of all steps related to the Project Online connectors in the flow:

sp-action2.pngsp-action1.png

The only thing I can think of is maybe there needs to be an action after Create the project site to check-in & publish, then re-checkout the project, run the action, and then check it back in?   I have tried small modifications to the syntax... For instance using double quotations instead of single in the body parameter, and adding a / before _api and/or removing it.  Nothing produces the desired outcome.

Expiscornovus
Super User II
Super User II

Hi @illmatic,

 

That is definitely a difference with my test. I am changing the description on an existing project.

 

If possible, test it without the create project action and use an existing project id instead.

 

Also make sure that your project is not checked out from a previous test:

https://docs.microsoft.com/en-us/project/check-in-enterprise-projects-in-project-server

 

Btw, on a side note. I am using this value as the site root url in my tests. I am assuming you are using the same kind of PWA root url?

https://contoso.sharepoint.com/sites/pwa

 

illmatic
Helper IV
Helper IV

I am using a site collection that has PWA enabled, but it is entitled 'projects' instead of PWA.   I don't think this should matter, considering in the flow above the Project is created just fine and it checks out the project itself just fine as well.

Since I have some other actions in this flow, I'll create a new one to see if this updates the fields.

illmatic
Helper IV
Helper IV

I deleted the actions related to Project Online initially and replaced with the following:

-Checkout Project [of previously created project]

- Send an http request to SP  

 

I used the same info as in the other screenshots.

 

Everything worked fine until I got to the 'Send a request to SP action.'  This resulted in the same error as follows:

 

{
  "status": 400,
  "message": "An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.\r\nclientRequestId: a5ebd749-5dd1-4867-8cbe-41134ff97c86\r\nserviceRequestId: eec1b79f-3066-0000-9a06-cbf2984ae53d",
  "source": "https://mysite.sharepoint.com/sites/pwatest/_api/ProjectServer/Projects('f5656d50-7c8d-eb11-bf98-00155de91211')/Draft",
  "errors": [
    "-1",
    "Microsoft.SharePoint.Client.InvalidClientQueryException"
  ]
}

 

This seems to me that I need to specify the fields in the body parameter.   

illmatic
Helper IV
Helper IV

I looked at the Enterprise Fields once more, I think I may have figured out the issue.  One of the columns is marked as required.  This means it probably cannot update the Project until those fields are actually filled in.   I'm going to unmark the required field, and see if I add my initial actions back if this resolves the issue.   

 

Thanks for your help thus far!  Much appreciated!

Expiscornovus
Super User II
Super User II

Hi @illmatic,

 

That sounds like you are getting close to the root cause. A required field makes sense. Keep me posted on your progress 🙂

Hey @Expiscornovus ,

That was the culprit!  Removing the required field resolved everything, and I was also able to add the 'Create a project' actions back.  Thank you so much for the assist!  

Expiscornovus
Super User II
Super User II

Hi @illmatic,

 

Great to hear that it is working. That is good news 🙂

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Users online (28,205)