none
Reading Custom Fields with ReadProject Routines RRS feed

  • Question

  • I am using ReadProject and passing Guid for project to read details about the project. Not all Custom Field Guids are coming up with the project record. 

    All the Custom Fields are part of PDPs that are under the EPT used to create the project. Any Clue, ideas or sample code?

    Wednesday, April 3, 2013 6:05 AM

Answers

  • You can read custom fields that have some value stored in it, but if custom field in your project is empty (contains no value on that project), then you will not see it.

    Here you can see how custom fields are updated:

    http://sharepoint1on1.blogspot.com/2013/01/project-server-update-custom-lookup.html

    Search for text:

    //if Custom field exists, but it is empty, then we need to add it to project

    you can see that, when field is empty, firstly, you must add it to project to update.

    Hope it helps.

    Wednesday, April 3, 2013 8:46 AM

All replies

  • You can read custom fields that have some value stored in it, but if custom field in your project is empty (contains no value on that project), then you will not see it.

    Here you can see how custom fields are updated:

    http://sharepoint1on1.blogspot.com/2013/01/project-server-update-custom-lookup.html

    Search for text:

    //if Custom field exists, but it is empty, then we need to add it to project

    you can see that, when field is empty, firstly, you must add it to project to update.

    Hope it helps.

    Wednesday, April 3, 2013 8:46 AM
  • Yes, I agree with Mario. This might be by design as to have less burden on the calls to the server.

    Thanks


    IN
    Thanks, Kashif

    Thursday, April 4, 2013 7:13 AM
  • Server Side

                    PublishedProject proj2Edit = projCollection.First();
                    if (!proj2Edit.IsCheckedOut)
                    {
    
                        DraftProject projCheckedOut = proj2Edit.CheckOut();
                        projContext.Load(projCheckedOut.Tasks);
                        projContext.ExecuteQuery();
                        DraftTaskCollection tskcoll = projCheckedOut.Tasks;
    
                        foreach (DraftTask tsk in tskcoll)
                        {
                            if ((tsk.Name != null) && (tsk.Name == "Name"))
                            {
                                projContext.Load(tsk.CustomFields);
                                projContext.ExecuteQuery();
                                foreach (CustomField cus in tsk.CustomFields)
                                {
                                    if (cus.Name == "MyCustomField")
                                    {
                                        string intname = cus.InternalName.ToString();
    // READING
                                        string cusvalue = tsk[intname].ToString();
    // WRITING
                                        tsk[intname] = "newValue";
                                        msg = "customfield  " + cusvalue;
                                    }
                                }
                            }
                        }
                        projCheckedOut.Publish(true);
                        QueueJob qJob = projContext.Projects.Update();
                        JobState jobState = projContext.WaitForQueue(qJob, 200);
                        string msg = "done";
                    }
                    else
                    {
                        string msg = "Project checked out";
                    }

    Friday, April 5, 2013 8:33 PM