This posting was inspired by a support call concerning custom fields – but does apply to other entities in the Project dataset and others. The question was around the QueueUpdateProject and QueueAddToProject web services calls that are part of the Project web service in the PSI. If you use the wrong call then the error message is usually helpful telling you you can’t add with the update call and vice versa. But the thing that does catch people out are the custom fields…
By default a project dataset will not contain any rows in the ProjectCustomFields data table unless they have either been set (through PWA, Project Professional or the PSI) or they contain formulae, or are based on a lookup table with a default value defined. So for a freshly created project (from Project Professional) when looking at Project Information it appears that all custom fields are there – and some may even look to have values (number fields will show 0) whereas in fact once saved there are no rows in the dataset for project custom fields (except as mentioned above – formulae based, and default lookup tables values). So if you want to set a custom field via the PSI your code should check if there is a row already present for that custom field (identify by the MD_PROP_UID or MD_PROP_ID) and if it is there then you can change the value and use QueueUpdateProject – and if it doesn’t exist then you will need to create a new blank project dataset and add a new project custom field row and set the values (including a new GUID for CUSTOM_FIELD_UID, the projects PROJ_UID and the MD_PROP_UID for the field you want to set) then use the QueueAddToProject.
(Update – Although this logic holds true for adding/updating tasks to a Project dataset you can in fact ADD a new custom field row to an existing project dataset and use the QueueUpdateProject method – and it will work. You do not need to use the QueueAddToProject method – although this will work too, assuming it only contains the additional custom field row! Thanks to Martin for pointing this out – through experience.)
Just to confuse the situation we have a bug currently when using the PSI or creating an Activity Plan/Proposal that can duplicate custom field rows. If you have any project level custom fields that use graphical indicators but do not have formulae then you can get duplicate custom field rows created for each of them. I’m not sure yet if the bug is they get created at all (as they do not get created in Project Professional projects) or that they appear twice. I will post an update when I have more information. For now a quick workaround is to not use graphical indicators for this type of field. Cleaning up existing ones may be a little more challenging and I would suggest a support call. Although this causes problems for the PSI when updating these duplicated rows (so this affects changes for Activity Plans , Proposals and use of the Edit Project Properties in PWA) you can still make changes in Project Professional through the Project Information dialog.
The errors you might see – (these are generic so you could see these errors for other root causes):-
When updating a custom field for an Activity Plan or Proposal you will get an error dialog box:-
Windows Internet Explorer
An error has occurred when saving your project to the server. Please contact your system administrator for assistance.
When updating a custom field through Project Center’s Edit Project Properties option the error will display at the top of the page in red:-
The project could not be saved due to the following reason(s):
An unknown error has occured (occurred is mis-spelled in the error).
When updating through the PSI this will result in a GeneralUnhandledException.
One final point – setting or updating a project custom field for an existing Project Professional created project through the PSI or Edit Project Properties will also introduce this problem. The extra duplicates will get added as well as the custom field you are setting.