0

Hello I want to Edit Custom Fields of Project Server 2010 Pragmatically but i don't know where i doing wrong. Following is the code,

Kindly Help me in this regard

ProjectSoapClient projectSvc = new ProjectSoapClient();
            CustomFieldsSoapClient customfieldSvc = new CustomFieldsSoapClient();
            CustomFieldDataSet fieldDefs = customfieldSvc.ReadCustomFields(string.Empty, false);

Guid projectId = new Guid(projGuid);
            ProjectDataSet projectDs = projectSvc.ReadProject(projectId, ListProjects.Project.DataStoreEnum.WorkingStore);

        foreach (ProjectDataSet.ProjectCustomFieldsRow cfRow in projectDs.ProjectCustomFields.Rows)
        {
            CustomFieldDataSet.CustomFieldsRow fieldDefinition = fieldDefs.CustomFields.Single(
                    cfd => cfd.MD_PROP_UID == cfRow.MD_PROP_UID);

            //if (cfRow.FIELD_TYPE_ENUM == 21 || cfRow.FIELD_TYPE_ENUM == 15) //if it is a choice field
            //{
                if (fieldDefinition.MD_PROP_NAME == "ProductCategory")
                {
                    cfRow.TEXT_VALUE = newValue;
                }
            //}
        }
        Guid sessionUid = Guid.NewGuid();
        Guid jobUid = Guid.NewGuid();
        if (!IsProjectCheckedOut(projectId))
        {
            projectSvc.CheckOutProject(projectId, sessionUid, "Updating CF");
            jobUid = Guid.NewGuid();
            projectSvc.QueueUpdateProject(jobUid, sessionUid, projectDs, false);
        }
        jobUid = Guid.NewGuid();
        projectSvc.QueuePublish(jobUid, projectId, true, SPContext.Current.Site.Url);
        projectSvc.QueueCheckInProject(jobUid, projectId, true, sessionUid, "Updating CF");
Mhd. Yasseen
  • 1,027
  • 3
  • 16
  • 27
  • There are several potential problems: if project is checked out - you does not call update, your projectDs could be mode than 1000 rows and update will fail on that, etc. Can you share what exactly "is going wrong"? Some error messages, at least something – melan Apr 11 '13 at 04:39
  • I appreciate your response. What I am doing is fetching all the Projects and its field values(custom & default) in a Grid as a web part on SharePoint Page. Fetching part is running absolutely fine but when i edit the above code is running fine, I debug the every statement of it, there is no error or exception in it but after update it did not change the value on Project server :( I am not understanding what i am doing wrong :(. Any idea?? – user1901417 Apr 11 '13 at 07:34

1 Answers1

0

Maybe it's because you publish the project first. It would also work only with the QueueCheckInProject function.

The other reason could be, that the row you're searching for with the iteration, isn't available yet and you have to add it to your project data set first!

And you should implement a wait for finishing the checkout, update and checkin!

Check out my blog entry for more details: http://www.geeklife.ch/dev/update-project-server-2010-customfields-over-psi/

Or my answer in this thread: Setting custom fields using the PSI - Microsoft Project Server

Community
  • 1
  • 1
cansik
  • 1,924
  • 4
  • 19
  • 39