0

I am trying to update a SharePoint task programmatically using CSOM. I am able to approve a task successfully but not sure how to update the comments.

The comments could be retrieved using ExtendedProperties as HashTable but I am unable to set the value for the same. How can I update the approval comments?

Below is the code to approve a task :

                using (ClientContext ctx = new ClientContext("http://abc/sites/TLS/low"))
            {
                Web web = ctx.Web;
                List oList = web.Lists.GetByTitle("Tasks");
                ListItem listitem = oList.GetItemById(784);
                ctx.Load(listitem);
                ctx.ExecuteQuery();
                Hashtable ht = GetExtendedPropertiesAsHashtable(listitem);
                listitem["Completed"] = true;
                listitem["PercentComplete"] = 1;
                listitem["Status"] = "Approved";
                listitem["WorkflowOutcome"] = "Approved";
                listitem["FormData"] = "Completed";
                //listitem["__ModerationComments"] = "Sdfs";
                //listitem["ows_FieldName_Comments"] = "Sdfs";
                //ht["ows_FieldName_Comments"] = "sdsds";
                listitem.Update();
                ctx.ExecuteQuery();
            }

Below is code to get the ExtendedProperties of a task item :

        public static Hashtable GetExtendedPropertiesAsHashtable(ListItem task)
    {
        if (task == null)
        {
            throw new ArgumentNullException();
        }
        Hashtable properties = new Hashtable();
        string extProperties = (string)task["ExtendedProperties"];
        if (!string.IsNullOrEmpty(extProperties))
        {
            var reader = new XmlTextReader(new StringReader("<Root " + extProperties + " />"))
            {
                WhitespaceHandling = WhitespaceHandling.Significant
            };
            reader.MoveToContent();
            if (!reader.HasAttributes)
            {
                return properties;
            }
            while (reader.MoveToNextAttribute())
            {
                string propName = reader.Name.Substring(4);
                properties[propName] = reader.Value;
            }
        }
        return properties;
    }
0

I dint believe it would be this simple. I just had to update the ExtendedProperties column.

listitem["ExtendedProperties"] = Convert.ToString(listitem["ExtendedProperties"]) + " ows_FieldName_Comments='" + "Test comment'";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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