none
Project Server Event handler Project OnPublished event calling the project PSI service for updating the project custom field not working RRS feed

  • Question

  • H i all,
    I'm facing an issue while updating the proejct server custom field from the PSI service. Please see the below issue

    Requirement:
    .There is a project custom field which is used in the project center webpart.

    I need to update that field from the external table (not related to project server).  This table is in the reporting database itself but not related to project server .  The data in the table is imported from some other external application.

    In order to meet this requirement,I came to know that  it is through PSI service we can update the custom field.  I have implemented one project server event handler code from which it calls the project PSI service for updating the custom field.   The code snippet is as below. The problem I am facing is that it is not setting the updated value.  Can you please give me some suggestions for resolving this issue. 

    SvcProject.ProjectDataSet.ProjectCustomFieldsRow cfRow = prjDataSetValues.ProjectCustomFields.NewProjectCustomFieldsRow();

     cfRow.PROJ_UID = myProjectId;
     cfRow.CUSTOM_FIELD_UID = Guid.NewGuid();
     cfRow.MD_PROP_UID = myCustomFieldId;
     cfRow.NUM_VALUE = 12345;
    prjDataSetValues.ProjectCustomFields.AddProjectCustomFieldsRow(cfRow);
    prjDataSetValues.ProjectCustomFields.AcceptChanges();
     updatedata = true; 

    Note:  This event handler will be invoked when the user publishes the project from the project center web part.
    Please help me to resolve this issue .

    Monday, November 24, 2014 6:53 AM

All replies

  • Hi,

    Are you getting any errors when the code is triggered? Also, the section of the code will work only if there are no values set already for the field.

    If the custom field is updated from an external source (I will call it external even though in your case your are  using a custom table in the reporting database) I would suggest using Powershell or some else (not an Event handler) to update the project fields on regular basis (daily, hourly, etc.). This way you can check if the project is checked out or not then update you fields.

    Below is a part of a PowerShel script I've used some time ago to update a field:

     

    $project = $svcPSProxy.ReadProjectEntities($projectUid, 32,"WorkingStore")  
                foreach($row in $project.ProjectCustomFields)
                {
                    if([System.Guid]$row.MD_PROP_UID -eq [System.Guid]$ecfGuidValue)
                    {
                        $row.TEXT_VALUE = [System.String]$abc
                        $foundCustomField = "1"
                    }
                }
                if ($foundCustomField -eq "0")
                {
                    $myNewCustomRow = $project.ProjectCustomFields.NewProjectCustomFieldsRow() 
                    $myNewCustomRow.PROJ_UID = [System.Guid]$projectUid
                    $myNewCustomRow.CUSTOM_FIELD_UID = [System.Guid]::NewGuid()
                    $myNewCustomRow.MD_PROP_UID = [System.Guid]$ecfGuidValue
                    $myNewCustomRow.TEXT_VALUE = [System.String]$abc
                    $project.ProjectCustomFields.AddProjectCustomFieldsRow($myNewCustomRow)

                }

    Hope this helps

    Paul

    Monday, November 24, 2014 9:27 AM
  • Can you please give the full code for that powershell? 

    Monday, November 24, 2014 11:52 AM
  • How are we getting the wcf proxy reference in poweshell script.  In the C3 code I'm adding the WCF proxy file for those PSI service I'm using file such as wcf.Project.cs and all in my project to to get the SVCProject namespace.

    How this can be done in the powershell script?

    Monday, November 24, 2014 12:08 PM
  • Hi Sabitha,

    I have extracted part of the code I've used to update a custom field for all projects(no master projects or sub projects)

    $ProjectSite = "http://project.contoso.com/PWA"
    $ecfGuidValue = "efcc9c8f-3f58-e411-9493-00155d00c808"    
    $svcPSProxy = New-WebServiceProxy -uri "$ProjectSite/_vti_bin/PSI/Project.asmx?wsdl" -useDefaultCredential 
        $EmptyGUID = [system.guid]::empty
        $ProjectList = $svcPSProxy.ReadProjectStatus("$EmptyGUID","WorkingStore","", "0").Project | format-table proj_uid -hidetableheaders | out-string -stream
        foreach ($projectUid in $ProjectList) 
        {
            $foundCustomField = "0"
            if ($projectUid -ne "")
    	    { 
                $sessionGuid = [System.Guid]::NewGuid()
                $jobGuid = [System.Guid]::NewGuid()
                $svcPSProxy.CheckOutProject($projectUid, $sessionGuid, "Updating Project") 
                $project = $svcPSProxy.ReadProjectEntities($projectUid, 32,"WorkingStore")  
                foreach($row in $project.ProjectCustomFields)
                {
                    if([System.Guid]$row.MD_PROP_UID -eq [System.Guid]$ecfGuidValue)
                    {
                        $row.TEXT_VALUE = [System.String]$Today
                        $foundCustomField = "1"
                    }
                }
                if ($foundCustomField -eq "0")
                {
                    $myNewCustomRow = $project.ProjectCustomFields.NewProjectCustomFieldsRow() 
                    $myNewCustomRow.PROJ_UID = [System.Guid]$projectUid
                    $myNewCustomRow.CUSTOM_FIELD_UID = [System.Guid]::NewGuid()
                    $myNewCustomRow.MD_PROP_UID = [System.Guid]$ecfGuidValue
                    $myNewCustomRow.TEXT_VALUE = [System.String]$Today
                    $project.ProjectCustomFields.AddProjectCustomFieldsRow($myNewCustomRow)
     
                }
                $jobGuid = [System.Guid]::NewGuid()
                $svcPSProxy.QueueUpdateProject($jobGuid, $sessionGuid, $project, $FALSE);                    
                $jobGuid = [System.Guid]::NewGuid()
                $svcPSProxy.QueueCheckInProject($jobGuid, $projectUid, $TRUE, $sessionGuid, "CheckIn Update...")      
            }

    You will just need to add your read of the custom table and identification of projects (not sure what you are using to identify projects - name, guid, CF) and then update the corresponding project.

    This part of the code was used in the Administrative backup on a custom schedule and by updating the custom fields all projects were archived (as all of them changed since last archive)

    Full code for archive can be found here (you may not need it)

    https://gallery.technet.microsoft.com/Server-Administrative-a2cbaa40

    Hope this helps

    Paul

    Monday, November 24, 2014 12:36 PM
  • Hi Paul,

    Before moving to the powershell i thought of exploring more.. In some of the project guid which has task , wile doing the checkout , checkin andqueuupdate it is getting the exception as follows:

    Project Server Service Application PSError: GeneralQueueJobFailed (26000).

    Any idea how to resolve this ?   In the mean time I'll start looking at the power shell code also

    Regards,

    Sabitha

    Tuesday, November 25, 2014 5:01 AM
  • Hi Sabitha,

    The error is quite generic. Any change you can get more details on the error from the queue or the SharePoint logs? Any particular step your code is failing?

    Paul

    Tuesday, November 25, 2014 3:17 PM
  • Hi,

     

    The most issue i saw in this is that i got the


    prjDataSetValues.ProjectCustomFields.Rows.Count0  . Why this data set returns zero row count event though it is having so many fields for the same guid is having so many custom field if i queries from the sql

    SELECT*

      FROM [ProjectServer_Published].[dbo].[MSP_PROJ_CUSTOM_FIELD_VALUES]
      where PROJ_UID='A9DDA7F4-FC78-4B6F-ACE6-13DDDCF784C5'
    From this I'm getting so many rows but from the code where the project datasetprjDataSetValues.ProjectCustomFields.Rows.Count returns 0. Please let me know what is this issue?

     

    Thursday, November 27, 2014 6:03 AM
  • Hi Paul,

    Currently the project customfield was updated which is not having any resource or task.

    For some project uid I'm getting the above error while calling the queueupdate.

    Project Server Service Application PSError: GeneralQueueJobFailed (26000).

    Could you please update me what is the method for resolving this ?


    • Edited by sabithad Thursday, November 27, 2014 12:22 PM error is not kept
    Thursday, November 27, 2014 12:21 PM