Remove permission of item using pnp

Hi,

I am trying to remove all permission when an item is created. I am using the code

fd.spSaved(function (result)
{
var id = result.Id;
var myfilter = "ID eq " + id;
var lines = pnp.sp.web.lists.getByTitle("Bid Type Lines");
lines.items.filter(myfilter).get().then(function(items)
{
alert(items.length);
for (var i = 0; i < items.length; i++)
{
lines.items.getById(items[i].Id).unshare();
}
});
});

This is removing the permission if I am submitting the form with full permission user(owner) but if I submit the form with a different user that has read-write access its not removing the permissions. The code is working I am getting the alert message as well.
My assumption is it needs full permission so can anyone confirm is it like that or not?

Hello @Ramiz,

Yes, you should have full control access level to the item to run unshare function.

@mnikitina

Is it possible to break inheritance each time a record creates regardless of who is creating a record?

@Ramiz,

You can create a flow to remove permission from the item. For instance, using Plumsail Actions. Please find more information here.

@mnikitina

I tried using an Instant flow When an HTTP request is received. I put the code on spSvaed function.

fd.spSaved(function (result)
{
    var obj = result.Id;
    alert(obj);
    var url = '..........triggers%2Fmanual%2Frun&sv=1.0&sig=ChHifPMGs-pN5glcO99hzzBTavOAn5M0_Oro2hVTzVA';
      
    fetch(url, {
                method: 'POST',
                body: JSON.stringify({id: obj}),
                headers:
                {
                    'Content-Type': 'application/json'
                }
            }) 
    
           
});

This works fine and removes the permission but the list from which I am trying to remove the permissions is a list or library control in plumsail. So If I am inserting record directly in the list its works all the time but If I insert a record using list or library control the flow doesnt trigger and sometimes it does. All I can think is because of list or library control this is happening.

Hello @Ramiz,

Most likely, the dialog window closes before the request is sent. ou can run your code on change event of List or Library control, like this:

fd.control('SPDataTable1').$on('change', function(changeData) {
    if (changeData.type === 'add') {
       //your function here
    }
    
});
1 Like