4

I am trying to determine how to use permissions for a project I am working on and I think I will have to use custom permissions for documents sets. I have read that too many custom permissions can cause performance issues though. If I could add a java script that caused the document set to re-inherit permissions once the status was marked as complete I think that would help keep the number of custom permissions down without requiring an administrator to go in and manually change each one. Is this possible?

Edit

Now I understand how to use the java script to restore permissions inheritance but I am still having trouble with understanding how to trigger this based on a status value I tried the code below but realized I need to use JSOM to get the value of the status category. I know how to get list data with JSOM but all the examples I have seen show outputting this data into a div. This scenario is a bit different and I'm not quite sure what to change.

function ResumeInheritance() {
if(status === "Closed") {
    JSRequest.EnsureSetup();
    var idValue = JSRequest.QueryString["ID"];
    var clientCtx = SP.ClientContext.get_current();
    var list = clientCtx.get_web().get_lists().getByTitle('Tasks');
    var item = list.getItemById(idValue);
    item.resetRoleInheritance();
    clientCtx.executeQueryAsync(function(){alert('success')},function(s,a){alert(a.get_message())});}
}
ResumeInheritance();
1

1 Answer 1

7
var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('Calendar');
var item = list.getItemById(121);
item.resetRoleInheritance();
ctx.executeQueryAsync(function(){alert('success')},function(s,a){alert(a.get_message())});

if you are opening the OOTB EditForm from a link on your custom CEWP, execute the following code on click of that link

<a class="itemlink" data-itemid="67" >item title</a>
    

the JS looks like

$('.itemlink').on('click',function(){
 var itemid = $(this).data('itemid');
   OpenPopUpPage('https://server/site/Lists/Tasks/EditForm.aspx?ID=' + itemid, function (sts, data) {
        if (sts === SP.UI.DialogResult.OK) { // item modified
            var ctx = new SP.ClientContext('siteurl');
            var item = ctx.get_web().get_lists().getByTitle('Tasks').getItemById(itemid);
            ctx.load(item);
            ctx.executeQueryAsync(function () {
                var statusval = item.get_fieldValues()['statuscolumninternalname'];
                if (statusval === 'closed') {
                    item.resetRoleInheritance();
                    ctx.executeQueryAsync(function () { alert('success - permissions inherited') }, function (s, a) { alert(a.get_message()) });
                }
            }, function (s, a) { alert(a.get_messsage()) });
        }
    });
});
12
  • I think you meant to have clientctx in place of ctx in the script, once I changed that it worked. This solves the main part of my question but I am still having trouble trying to figure out how to trigger it based on the status value. I will update my question in a second, I think I need to use JSOM for this as well?
    – James11
    Commented Aug 4, 2015 at 17:04
  • @james11, that is only a variable name. The variable is declared in the snippet in this answer Commented Aug 4, 2015 at 18:36
  • Sorry if I wasn't clear, I realized that was just a variable name, I was just pointing out the variables didn't match up before the edit, they needed to all be either ctx or clientCtx. The only part I'm unsure about is how to use JSOM to get the value of the status so this function runs only if a certain value is selected.
    – James11
    Commented Aug 5, 2015 at 13:49
  • Do you want to reset the the permissions when user changes the value of Status column from OOTB EditForm? When the code needs to be triggered? Commented Aug 5, 2015 at 17:21
  • Exactly, the idea is once the user changes the status to Closed the permissions would reset.
    – James11
    Commented Aug 5, 2015 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.