Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We've created a webpart and user control that uses a sharepoint people picker to save AD accounts to a project custom field.

To save, we've hooked into the ProjectSave event (click 'Save' on the ribbon) using a page component.

After the save callback is triggered and we've updated the custom field, PWA complains that, "the project is out of date" and has been, "updated in another session." That's obviously our doing.

Our suspicion is that someone tracks the last updated date/time and notices that it's changed since being created.

Thanks for any suggestions.

Update

void OnSaveProject()
    {
        ProjectDataSet projectDataSet = ProjWeb.project.ReadProjectEntities(ProjectUid, (int)(ProjectEntityType.ProjectCustomFields | ProjectEntityType.Project), SvcProject.DataStoreEnum.PublishedStore);
        //ProjectDataSet projectDataSet = ProjWeb.project.ReadProject(ProjectUid, SvcProject.DataStoreEnum.PublishedStore);
        ProjectDataSet.ProjectRow project = projectDataSet.Project[0];

        if (!project.IsPROJ_CHECKOUTBYNull() && project.PROJ_SESSION_UID != null)
        {
            Guid fieldGuid;                

            // skip if this customfield is not set
            //
            if (!String.IsNullOrEmpty(ProjectServerCustomFieldAccounts))
            {
                fieldGuid = ProjWeb.customFields.GetCustomField(ProjectServerCustomFieldAccounts);

                if (!ProjWeb.SetCustomValue(projectDataSet, project.PROJ_SESSION_UID, fieldGuid, PeopleEditor.CommaSeparatedAccounts))
                {
                    PpWebPart.Log("Error at SetCustomValue to value" + PeopleEditor.CommaSeparatedAccounts);
                }
           }
        }

Then, SetCustomValue:

public bool SetCustomValue(SvcProject.ProjectDataSet forProject, Guid sessionUId, Guid field, String value)
    {
        Guid ciJobId = Guid.NewGuid();

        foreach (SvcProject.ProjectDataSet.ProjectCustomFieldsRow r in forProject.ProjectCustomFields)
        {
            if (r.MD_PROP_UID.Equals(field))
            {
                if (r.TEXT_VALUE.Equals(value)) return false;
                r.TEXT_VALUE = value;

                project.QueueUpdateProject(ciJobId, sessionUId, forProject, false);
                queueSystem.WaitFor(ciJobId);

                return true;
            }
        }

        return false;
    }
share|improve this question

1 Answer 1

Make sure that your custom Save logic isn't calling Update(). If it is, then what is happening is that the page is attempting to save from the known state 'XYZ', hits your Update() which then changes the underlying item from 'XYZ' into state 'ABC'. However, the Update() from the submit itself hasn't fired yet. When it does, it is expecting to update item in state 'XYZ' but instead finds state 'ABC'. To the code, this means that the underlying item has been changed which means that the changes being submitted contain outdated data along with the updates. SharePoint fails the second update in order to prevent data loss.

share|improve this answer
    
OK. If we don't call update, will the changes persist in the data set until the submit calls Update()? –  Joel Jul 20 '12 at 17:08
    
I can't really answer that without knowing the code, however, if the fields you need saved are in the page being submitted then they will be saved –  Dave Wise Jul 20 '12 at 17:12
    
The fields themselves are not on the PDP. The idea is to have the people editor/web part handle selecting accounts and to save to a project custom field. Ideally the custom field would not need to be on the PDP. –  Joel Jul 20 '12 at 17:14
    
Which Update do you mean? PSI.project.QueueUpdateProject? –  Joel Jul 20 '12 at 17:27
    
Then you might need to hook into a later event in order to do your Update or possibly move this functionality to an EventReceiver –  Dave Wise Jul 20 '12 at 17:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.