Please specify what version of the library you are using: [ 2.0.9 ]
Please specify what version(s) of SharePoint you are targeting: [ Online, spfx v1.10.0 ]
Hi
I have developed a field customizer. I am writing the value of the field after executing some logics depending on some values from an API. What I am trying to do is update only the value of the field and keep the modified date and modified by intact. I found validateUpdateListItem can do that. Below is the code snippet for update inside then of getAllItems which is called in the onInit method of field customizer extension.
`
let newValues: IListItemFormUpdateValue[] = [];
newValues.push({
FieldName: "SPFxStatusUAT",
FieldValue: text,
});
newValues.push({
FieldName: "Modified",
FieldValue: item.FieldValuesAsText.Modified,
});
newValues.push({
FieldName: "Editor",
FieldValue: JSON.stringify([{ Key: item.Editor.Name }]),
});
sp.web.lists
.getByTitle(listTitle)
.items.getById(item.ID)
.validateUpdateListItem(newValues, true)
`
It is working fine, if I am logged in as the owner of the site. But if I am logged in as a member user, the 'SPFxStatusUAT' field value gets updated normally but modified by and date is also updated to current user and time rather than preserving old values.
Please can anyone point me in the proper direction as to what could be the problem?
I did some research and SIG demo regarding the question, you can check sp-sig-20180705-demo. The repo contains a link to the article, and SIG call recording somewhere, and samples which might be helpful.
The user access level is important, every random user can't update these systems fields. The behavior you're describing is a by design. For preserving such metadata, the logic should be moved to the server-side and running with service account privileges.
Yah I actually got the reference to validateUpdateListItem method from your linkedin article. And user access level editability is understandable. Could you please suggest how or what library should I look for updating these meta? We also have an azure functions solution tied in to the system.
Could you please suggest how or what library should I look for updating these meta? We also have an azure functions solution tied in to the system.
I'd say PnPjs in an Azure Function secured with AAD. That approach: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient-enterpriseapi
It's not about the library, but running code with elevated privileges.
Thanks a lot. I used the sharepoint v1 rest api for "validateUpdateListItem" in my azure functions solution. It was just one operation so I thought not adding an entire library for just one operation. Also the functions solution is in C#.
Most helpful comment
I'd say PnPjs in an Azure Function secured with AAD. That approach: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient-enterpriseapi
It's not about the library, but running code with elevated privileges.