In this post we will discuss how we can resolve the below issue which comes when trying to update the Approval status column as well as some properties of the list item in SharePoint online using csom ( .Net managed object model code).
Recently we were working on a SharePoint project where we need to update item properties of a list item where we also need to update the approval status of the item using csom (.Net managed object model code). We were trying the below code:
if (item != null)
{
item[“Columnname”] = “Column Value”;
item[“Columnname 1”] = “Column 1 Value”;
item[“Columnname 2”] = “Column 2 Value”;
item[“_ModerationStatus”] = “0”;
item.Update();
context.ExecuteQuery();
}
In the ExecuteQuery() method it gave the below error:
You cannot change moderation status and set other item properties at that same time.
Solution:
We changed the code like below. Basically we change first update the item custom column properties and then we change the _ModerationStatus properties value.
if (item != null)
{
item[“Columnname”] = “Column Value”;
item[“Columnname 1”] = “Column 1 Value”;
item[“Columnname 2”] = “Column 2 Value”;
item.Update();
context.ExecuteQuery();
item[“_ModerationStatus”] = “0”;
item.Update();
context.ExecuteQuery();
}
Read some sharepoint online tutorials:
- Steps to delete sites sub sites using .Net managed object model in SharePoint online
- How to check if list exists in SharePoint online using .Net managed object model CSOM?
- SharePoint Online Create choice type site column and add mapping inside SharePoint hosted add-in using visual studio 2015
After this the error did not come. Hope this will be helpful.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com