none
Synch Project Online Resource's Timesheet Manager with User Defined in Active Directory RRS feed

  • Question

  • I'm able to update the Timesheet Manager for one resource.  But I keep getting Exception when I tried to loop through all the Resources in my instance.  I'm soooo close.  What am I missing?

    Microsoft.SharePoint.Client.ServerException: 'PJClientCallableException: ResourceCannotSetTimesheetManagerOnSpecifiedResource
    ResourceCannotSetTimesheetManagerOnSpecifiedResource'

    Guid resUID = new Guid("07f5402d-c89a-ea11-b091-00155d1c6624");  // Kalerine
     
                projContext.Load(projContext.EnterpriseResources.GetByGuid(resUID));
                projContext.ExecuteQuery();
                EnterpriseResource rsc = projContext.EnterpriseResources.GetByGuid(resUID);
                //projContext.ExecuteQuery();
                String managerAD = LookupADManager(rsc.Email);
                if (!managerAD.Equals(""))
                {
                    User manager = LookupTimesheetManager(managerAD);
                    rsc.TimesheetManager = manager;
                    projContext.EnterpriseResources.Update();
                    projContext.ExecuteQuery();
                }

    private static void SynchResourceTimesheetManager()
            {
                var resources = projContext.EnterpriseResources;
                projContext.Load(resources);
                projContext.ExecuteQuery();
                var j = 0;
                int numResInCollection = projContext.EnterpriseResources.Count();
     
                if (numResInCollection > 0)
                {
     
                   
                    //***** Work with one AD attribute for now ******/
                    foreach (EnterpriseResource rsc in resources)
                    {
     
                        log.Debug("\ncount: {0}. ID:{1}   Name:{2} \tEmail:{3} Time Manager: {4} Base Calendar: \n"
                            , j++, rsc.Id, rsc.Name, rsc.Email, rsc.TimesheetManager, rsc.BaseCalendar);
     
                        projContext.Load(projContext.EnterpriseResources.GetByGuid(rsc.Id));
                        projContext.ExecuteQuery();
     
                        var rscEdit = projContext.EnterpriseResources.GetByGuid(rsc.Id);
     
                        log.Debug("\nEditing : {0}. ID:{1}   Name:{2} \tEmail:{3} Time Manager: {4} Base Calendar: \n"
                            , j++, rscEdit.Id, rscEdit.Name, rscEdit.Email, rscEdit.TimesheetManager, rscEdit.BaseCalendar);
                       
                        String managerAD = LookupADManager(rsc.Email);
                        if (!managerAD.Equals(""))
                        {
                            User manager = LookupTimesheetManager(managerAD);
                            //if (rscEdit.IsCheckedOut)
                            //{
                                rscEdit.TimesheetManager = manager;
                                projContext.EnterpriseResources.Update();
                                projContext.ExecuteQuery();
     
                                projContext.Load(projContext.EnterpriseResources.GetByGuid(rsc.Id));
                                projContext.ExecuteQuery();
     
                                rscEdit = projContext.EnterpriseResources.GetByGuid(rsc.Id);
     
                                log.Debug("\nVerify : {0}. ID:{1}   Name:{2} \tEmail:{3} Time Manager: {4} Base Calendar: \n"
                           , j++, rscEdit.Id, rscEdit.Name, rscEdit.Email, rscEdit.TimesheetManager, rscEdit.BaseCalendar);
     
     
     
     
                            //}
                        }
     
                    }
                    //projContext.EnterpriseResources.Update();
                    //projContext.ExecuteQuery();
                }

    Thursday, September 10, 2020 3:28 PM