none
Resource custom fields update code RRS feed

  • Question

  • Hello forum members,

    we have custom fields for resources and I need help figuring out how to write a job that updates resource custom fields after AD sync have been completed.

    Can anyone provide any code examples? 

    i found this code that will check out a resource and update its name: http://msdn.microsoft.com/en-us/library/websvcresource.resource.updateresources(v=office.12).ASPX

    but how would you handle a custom field? How would you look up a custom field ID ? what code would you recommend to loop it through all changed resources? (if there are thousands of them)

    is there a way to set this up to run once a day?

      resourceSvc.CheckOutResources(new Guid[] { resourceDs.Resources[0].RES_UID });
    
                // Update the resource name of the first row.
                Console.WriteLine ("Modifying resource " + resourceDs.Resources[0].RES_ID + " (" + resourceDs.Resources[0].RES_NAME + ")");
                resourceDs.Resources[0].RES_NAME += " Modified at: " + DateTime.Now.ToShortTimeString();
    
                // Send the update to the server and automatically check in the changed row
                resourceSvc.UpdateResources(resourceDs, false, true);


    tatiana


    Monday, July 7, 2014 3:22 PM

Answers

  • Hi

    You can either create a console application or create an event handler to perform the below steps

    Read all the resources ,

    update the custom field based on create Date \Modified Date

    resourceDS = SResource.ReadResources(string.Empty, false);
    foreach (SVCResource.ResourceDataSet.ResourcesRow rsd in resourceDS.Resources)
                {

                    SVCResource.ResourceDataSet ResData = SResource.ReadResource(rsd.RES_UID);
                    fd = false;

                    DateTime dt;
                    dt=DateTime.Now.AddDays(-1);
                    if (ResData.Resources[0].CREATED_DATE > dt)
                    {

                        SResource.CheckOutResources(new Guid[] { rsd.RES_UID });
                        //add a new custom fields row and assign the value
                        SResource.UpdateResources(ResData, false, true);
                    }
                }

    Console application can be scheduled using windows scheduler

    Event handler can be triggered for the below event

    Event Source:                     Admin                    
    Event Name:                     AdSyncERPSynchronized

    --Hope this helps

     


    Thanks --Ajith

    Wednesday, July 16, 2014 3:17 PM
    Moderator

All replies

  • PS. i found a way to get a custom field guid by going to EditCustomField.aspx and copy it from url

    tatiana

    Monday, July 7, 2014 9:49 PM
  • Hi

    You can either create a console application or create an event handler to perform the below steps

    Read all the resources ,

    update the custom field based on create Date \Modified Date

    resourceDS = SResource.ReadResources(string.Empty, false);
    foreach (SVCResource.ResourceDataSet.ResourcesRow rsd in resourceDS.Resources)
                {

                    SVCResource.ResourceDataSet ResData = SResource.ReadResource(rsd.RES_UID);
                    fd = false;

                    DateTime dt;
                    dt=DateTime.Now.AddDays(-1);
                    if (ResData.Resources[0].CREATED_DATE > dt)
                    {

                        SResource.CheckOutResources(new Guid[] { rsd.RES_UID });
                        //add a new custom fields row and assign the value
                        SResource.UpdateResources(ResData, false, true);
                    }
                }

    Console application can be scheduled using windows scheduler

    Event handler can be triggered for the below event

    Event Source:                     Admin                    
    Event Name:                     AdSyncERPSynchronized

    --Hope this helps

     


    Thanks --Ajith

    Wednesday, July 16, 2014 3:17 PM
    Moderator