Cascade Skyline - with Microsoft Logo and Project Support header - author Brian Smith

To Add or Update - That is the Question. The PSI and custom fields - Updated

To Add or Update - That is the Question. The PSI and custom fields - Updated

Rate This
  • Comments 49

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.
[GeneralUnhandledException]

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.

Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post
  • Thanks for sharing Richard.  I'll see if we know about that one...

  • Dear Brian,

    Here the same problem persists, but I am not getting what I am missing in my code.

    I am updating Project Custom Field (P_CF) value for selected projects from drop down list.

    If P_CF is not having lookup and data type as Text, I am able to update it.

    But, If P_CF is having lookup and data type as Text, I am getting exception in QueueUpdateProject method as:

    ProjectServerError(s) LastError=CustomFieldInvalidTypeColumnFilledIn Instructions: Pass this into PSClientError constructor to access all error information.

    Example: CF=Department and Lookup Table associated with CF (Department) is LT_Department containing values as

    Dept1

    Dept2

    Dept3.

    What I want to do: For a project, selected Department value= Dept1.

    I want to update it by some other existing value (say Dept2).

    Here is my code:

    PSLibrary.Filter cfFilter = new PSLibrary.Filter();

    cfFilter.FilterTableName = lt_DS.LookupTables.TableName;

    ds.Add(new PSLibrary.Filter.Field(lt_DS.LookupTableTrees.TableName,

                  lt_DS.LookupTableTrees.LT_VALUE_TEXTColumn.ColumnName));

    cfFilter.Fields.Add(new PSLibrary.Filter.Field(lt_DS.LookupTableTrees.TableName,l

    t_DS.LookupTableTrees.LT_VALUE_DESCColumn.ColumnName,               Microsoft.Office.Project.Server.Library.Filter.SortOrderTypeEnum.Asc));

               PSLibrary.Filter.FieldOperator criteria =

           new Microsoft.Office.Project.Server.Library.Filter.FieldOperator

           (PSLibrary.Filter.FieldOperationType.Equal, "LT_NAME",

           new string[] { "LT_Department" });

               cfFilter.Criteria = criteria;

               // The GetXml method creates the xmlFilter parameter for ReadCustomFields

               lt_DS = webSvcLT.ReadLookupTables(cfFilter.GetXml().ToString(), false, 0);

               DataTable dtLTValue = null;

               dtLTValue = lt_DS.Tables[0];

               ddlSelectedLookupValue.DataTextField = "LT_VALUE_TEXT";

               ddlSelectedLookupValue.DataValueField = "LT_VALUE_DESC";

               ddlSelectedLookupValue.DataSource = dtLTValue;

               ddlSelectedLookupValue.DataBind();

    bool found = false;

                //Loop through the custom field rows

                foreach (WebSvcProject.ProjectDataSet.ProjectCustomFieldsRow CFrow in lo_projDS.ProjectCustomFields)

                {

                    if (CFrow.MD_PROP_UID == cfId)

                    {

                        //Update field value

                        //CFrow.TEXT_VALUE = cfValue;

                        //CFrow.CODE_VALUE = selectedLookupValue.ToString();

                        CFrow.TEXT_VALUE = selectedLookupValue.ToString();

                        found = true;

                        break;

                    }

                }

    Request you to help in this.

    Regards,

    Shravan

  • Hi Shravan, you cannot update the text value of a custom field that uses a lookup table - you can only update the code value - which will then use the appropriate text from the lookup table in PWA and Project Pro as appropriate..  So you need to get the code value of the lookup text you want to set and set that.  I'm sure I had a sample in another blog post - I'll see if I can find it.

    Best regards,

    Brian.

  • This is the post I was thinking of:

    blogs.msdn.com/.../setting-custom-field-values-using-the-psi.aspx

Page 4 of 4 (49 items) 1234