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?
2 Answers
If i'm not wrong you cannot use something similar with REST API. All request will be executed by the current user.
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:
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.