7

I know the new CSOM & PowerShell allows making calls to SystemUpdate (https://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365-august-2016-updated) - however is there a REST equivalent that I can use from SharePoint Workflow?

1
  • Hey, did you found any solution for this? – ThinkB4Code Jun 15 '18 at 16:15
0

If i'm not wrong you cannot use something similar with REST API. All request will be executed by the current user.

0

The similar question has been discussed here

It says, using REST API we can not implement this.

"As far as I know, and as I have already wrote in this thread, the SystemUpdateand the UpdateOverwriteVersionmethods are not implemented in the Client OM and in the REST API. If you decompile the Microsoft.SharePointassembly (for example using Reflectoror JetBrains dotPeek), you can see the lack of the attributes on these methods, that would be needed to client access."

However, even though there is no direct way to handle the System Update in REST API, we can achieve it by the below work around:

import { Item, ListItemFormUpdateValue, PermissionKind } from '@pnp/sp';
import { format } from 'date-fns';

export const dateToFormString = (dateTime: Date | string): string => {
  return format(dateTime, 'M/D/YYYY h:m A');
};

export const loginToFormString = (userName: string): string => {
  return JSON.stringify([{ Key: userName }]);
};

export const systemUpdate = async (item: Item, formUpdateValues: ListItemFormUpdateValue[]) => {

  const permissions = await item.getCurrentUserEffectivePermissions();
  if (!item.hasPermissions(permissions, PermissionKind.ManagePermissions)) {
    throw new Error('403 - Access denied. Full Control permissions level is required for performing this operation.');
    // Having write permission but not managing, the method will ignore Editor and Modified values and update them with actual data
  }

  const { Author: { Name }, Created: Modified } = await item.select('Created,Author/Name').expand('Author').get();

  const sysUpdateData = [
    { FieldName: 'Editor', FieldValue: loginToFormString(Name) },
    { FieldName: 'Modified', FieldValue: dateToFormString(new Date(Modified)) }
  ];

  const result = await item.validateUpdateListItem(formUpdateValues.concat(sysUpdateData), true);

  const errors = result.filter(field => field.ErrorMessage !== null);
  if (errors.length > 0) {
    throw new Error(JSON.stringify(errors));
  }

  return result;
};

This example updates item using nothing else but REST API. REST API "validateUpdateListItem" method creates no version on change. And if provide Editor and Modified fields with previously existed values the result will be close to system update.

Reference URL:

System update via REST API

Recap: what is item.update() and item.system.update()?

Item.update method create a new version of item and update some other field also in a list like modified,modifiedby,created,,createdby. While item.systemupdate() does not modify these fields.

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.