Expand Minimize

SPC019010: You must call Update() to persist any changes to the ListItem object.

When modifying the ListItem object you need to call ListItem.Update() in order to persist the changes to the object.

CheckId SPC019010
TypeName UpdateAfterModifyingListItemObject
Severity Warning
Type Assembly

Bad Practice

using (var context = new ClientContext("http://yoursite"))
{
    // Assume that the web has a list named "Announcements".
    List announcementsList = context.Web.Lists.GetByTitle("Announcements");

    // Assume there is a list item with ID=1.
    ListItem listItem = announcementsList.GetItemById(1);

    // Write a new value to the Body field of the Announcement item.
    listItem["Body"] = "This is my new value!";
    context.ExecuteQuery();
}


Good Practice
using (var context = new ClientContext("http://yoursite"))
{
    // Assume that the web has a list named "Announcements".
    List announcementsList = context.Web.Lists.GetByTitle("Announcements");

    // Assume there is a list item with ID=1.
    ListItem listItem = announcementsList.GetItemById(1);

    // Write a new value to the Body field of the Announcement item.
    listItem["Body"] = "This is my new value!";

    // Update the listItem object with ListItem.Update() and then call ClientContext.ExecuteQuery()
    listItem.Update();
    context.ExecuteQuery();  
}

To suppress this violation in managed code add the following attribute to the method which contains the instruction (available since SPCAF version v5.2). Learn more about SuppressMessage here.

// Important: Ensure to have #define CODE_ANALYSIS at the beginning of your .cs file
[SuppressMessage("SPCAF.Rules.ManagedCSOM.CSOMCorrectnessGroup", "SPC019010:UpdateAfterModifyingListItemObject", Justification = "Provide reason for suppression here")]
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.