1

I want to update Property Bag items with pnp-core js. I can get the property bag items by the following code -

pnp.sp.web.select('AllProperties').expand('AllProperties').get()

But what is the code to update Property Bag items?

1

Theoretically, you should be able to leverage the processQuery rest endpoint, and perform a query like the one below, in order to update a site custom property bag:

    import { SPHttpClient, SPHttpClientResponse, ISPHttpClientOptions } from '@microsoft/sp-http';
    [...]
    let myPropertyBag ="customPropbag1"
    let myNewPropBagValue ="new value"
    let clientServiceUrl = `${this.siteAbsoluteUrl}/_vti_bin/client.svc/ProcessQuery`;
    let data = `<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="Javascript Library"><Actions><ObjectPath Id="1" ObjectPathId="0" /><ObjectPath Id="3" ObjectPathId="2" /><ObjectPath Id="5" ObjectPathId="4" /><Method Name="SetFieldValue" Id="6" ObjectPathId="4"><Parameters><Parameter Type="String">${myPropertyBag}</Parameter><Parameter Type="Number">${myNewPropBagValue}</Parameter></Parameters></Method><Method Name="Update" Id="7" ObjectPathId="2" /><Query Id="8" ObjectPathId="2"><Query SelectAllProperties="true"><Properties /></Query></Query><Query Id="9" ObjectPathId="4"><Query SelectAllProperties="true"><Properties><Property Name="edrms_eFolderId" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><StaticProperty Id="0" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /><Property Id="2" ParentId="0" Name="Web" /><Property Id="4" ParentId="2" Name="AllProperties" /></ObjectPaths></Request>`;
    let httpPostOptions = {
            headers: {
              'accept': 'application/json',
              'content-type': 'application/json',
              'X-RequestDigest': this.formDigest
            },
            body: data
          };

    let serviceResponse: SPHttpClientResponse = await this.spHttpClient.post(clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions);
[...]

and then

let serviceJSONResponse: Array<any> = await serviceResponse.json();
| improve this answer | |
0

Unfortunately, property bags are read-only in RESP API, so it's not possible right now, as the ideology of PnP JS Core is to be a wrapper around REST API only. JSOM API should be used instead now for writing to property bags.

| improve this answer | |

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.