none
CSOM - update custom field based on lookup table RRS feed

  • Question

  • hello forum members

    can anyone show me how to update a resource custom field that uses a value that is picked up from a Lookup table by using CSOM? 

    i can't seem to find any examples online.


    tatiana



    Monday, December 28, 2015 10:20 PM

Answers

  • ok. i got the answer from Microsoft support and it works 

    here it is

    var cfInternalName = "Custom_aaf4156c7804e511943500155d569905";

                foreach (EnterpriseResource res in resources)

                {

                    string[] Newval = new string[] { "Entry_333982d27604e511943500155d569905" };     //Lookup table row value UID without "-"   and small letters                                             

                    res[cfInternalName] = Newval;                 

                    

                }

                projContext.EnterpriseResources.Update();

                projContext.ExecuteQuery();


    tatiana


    Wednesday, January 6, 2016 8:51 PM

All replies

  • Did you try what I've written last post on one of your latest posts?

    https://social.msdn.microsoft.com/Forums/en-US/e25eeee3-22af-498e-b6cd-0a628dd46aea/csom-create-new-custom-field-row?forum=project2010custprog#db53bd30-2966-4829-8bfb-36d6788aab4b

    Try it with this method:

    rs.SetCustomFieldValue(cfPersonType.InternalName, "Custom Field Value Here");

    What you have to check if this also works for updates on existing custom field values.

    Tuesday, December 29, 2015 9:13 AM
  • Sansha,

    when i tried that i am getting a compiler error: 

    Error 4 'Microsoft.ProjectServer.Client.EnterpriseResource' does not contain a definition for 'SetCustomFieldValue' and no extension method 'SetCustomFieldValue' accepting a first argument of type 'Microsoft.ProjectServer.Client.EnterpriseResource' could be found (are you missing a using directive or an assembly reference?)


    tatiana

    Tuesday, December 29, 2015 4:06 PM
  • this is the code i have so far. it complies and runs, but when query executes the field ends up being empty and not updated. I dont see any errors and the console.writeline shows correct value. could it be that the value saved, but not showing somehow?

    //update flsa_cd
                CustomField cfFLSA_CD;
                String cfFLSA_CDInternalName;

                cfFLSA_CD = customFields.First(c => c.Name == "Resource_FLSA_CD");

                cfFLSA_CDInternalName = cfFLSA_CD.InternalName;

                if (row["flsa_cd"] != null)
                {
                    if (row["flsa_cd"].ToString() != String.Empty)
                    {
                        if (rs[cfFLSA_CDInternalName].ToString() != (row["flsa_cd"]).ToString())
                        {
                            rs[cfFLSA_CDInternalName] = row["flsa_cd"].ToString(); //does not work

                            resources.Update();
                            projContext.ExecuteQuery();

                            Console.WriteLine("Update FLSA_CD type to " + rs[cfFLSA_CDInternalName].ToString());
                        }
                    }
                }


    tatiana







    Tuesday, December 29, 2015 5:41 PM
  • i just checked the database and no, the value was NOT updated



    tatiana

    Tuesday, December 29, 2015 6:39 PM
  • ok. i got the answer from Microsoft support and it works 

    here it is

    var cfInternalName = "Custom_aaf4156c7804e511943500155d569905";

                foreach (EnterpriseResource res in resources)

                {

                    string[] Newval = new string[] { "Entry_333982d27604e511943500155d569905" };     //Lookup table row value UID without "-"   and small letters                                             

                    res[cfInternalName] = Newval;                 

                    

                }

                projContext.EnterpriseResources.Update();

                projContext.ExecuteQuery();


    tatiana


    Wednesday, January 6, 2016 8:51 PM
  • I just want to say thank you for this post. I have been struggling relentlessly for the last 2 weeks trying to update a custom field linked to a table using CSOM. This did it for me.
    Thursday, January 2, 2020 12:22 PM