How to set property in property bag on root site collection using JSOM?

Copper Contributor

I am trying to update/create property in PropertyBag. Its working fine on classic experience (developer site and document center) but its not allowing application to start on modern site collections(root site, communication site and team site) and its not setting property in PropertyBag.

When I try to run application root site collection after installation its throwing this error

Access denied. You do not have permission to perform this action or access this resource.

Please tell me how can I set property in property bag for root site, communication site and team site.

 

var context = SP.ClientContext.get_current();
        var web = LawApp.Repositories.getWeb(context, hostUrl);
        var props = web.get_allProperties();

        props.set_item("CurrentVersion", 2002);
        web.update();
        context.executeQueryAsync(success, fail);

 

3 Replies
Try using PnPjs, see link below for more information:

https://pnp.github.io/pnpjs/

I don't have any idea about PnPjs. Can you please tell me any other way?Its working fine if I install app on document center or developer site but it says access denied if I install it on root site, communication site or team site.@ArefHalmstrand 

@Asjad_Ali 
I solved it by change the value of "CurrentVersion" to string because property bag does not take integer values. You can check this link too.

https://sharepoint.stackexchange.com/questions/171244/setting-propertybag-values-in-sharepoint-onlin...