Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting SPListItem field in ItemUpdating not persisted with SystemUpdate(false)
    primarykey
    data
    text
    <p>I have a custom list definition with an event receiver that overrides ItemUpdating. The list has <em>content approval</em> turned on, along with <em>create major and minor versions</em>. </p> <p>If the item is being approved, I want to set a boolean field (Is Published?) without affecting the version and approval status. I understand <strong>SystemUpdate(false)</strong> is suppose to do this, however it does not persist the bool value. If I use <strong>Update()</strong> or <strong>SystemUpdate()</strong>, the value is persisted but it doesn't set the approval status to <em>Approved</em> and throws the following error: </p> <blockquote> <p>The file [filename] has been modified by [user] on [date].</p> </blockquote> <pre><code>public override void ItemUpdating(SPItemEventProperties properties) { base.ItemUpdating(properties); EventFiringEnabled = false; try { if (IsChangingToApproved(properties)) { if (!Validate(properties)) {// This person can't approve properties.ErrorMessage = "You don't have appropriate permissions."; properties.Status = SPEventReceiverStatus.CancelWithError; properties.Cancel = true; } else {// Set the IsPublished flag to true var isPublishedField = properties.List.Fields["Is Published?"]; if (isPublishedField != null) { properties.ListItem[isPublishedField.InternalName] = true; // Doesn't update bool, ItemUpdating event functions normally properties.ListItem.SystemUpdate(false); // Updates bool, but ItemUpdating event does not complete //properties.ListItem.Update(); //properties.ListItem.SystemUpdate(); } } } } catch (Exception ex) { return; } finally { EventFiringEnabled = true; } } </code></pre> <p>Things I've tried:</p> <ul> <li>Updating the listItem with a <code>using Site/using Web</code> block instead of updating the item from the properties.</li> <li>Setting the properties.AfterProperties["Is Published?"] field.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload