To make fields read only based on assignment group

moulik1
Kilo Guru

Hello All,

In our scenario we have created a list of tasks and all the tasks are assigned to some assignment groups.

If the user is from ABC group and when he tries to open a task (which is assigned to another group) from a list of tasks in requested item then all the fields of that task should be read only and an alert message has to be shown that you don't have access to this task.

how can we achieve the above scenario?

Thanks.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Moulik,



ACL's is the best way to achieve this. You can restrict the write access to the table. Here is the script section you can use.


answer= checkIfMember();


function checkIfMember()


{


  var current_user= gs.getUser();


  return current_user.isMemberOf(current.assignment_group.name);


}






View solution in original post

12 REPLIES 12

First option I would prefer is ACL. If not the other way is client script+GlideAjax


Thanks for your assistance ,



can you please help me in getting it using a client script .



I am using g_user.userName to get the current user


how to get the groups for the current logged in user so that we can restrict him from viewing the tasks.


HI Moulik,



Any reason why you don't want to go with ACL.


However you can return true or false from script include and then use the script pasted by Alex below.


So basically you can pass the current group from client script and then at the server side check if user is a member of the group or not.


Getting a User Object - ServiceNow Wiki


salemsap
Tera Expert

Hi Moulik,



write a script include and check whether the login person belongs to current assignment group and return some string from script include.



if(return string == 'yes')


{


var fields = g_form.getEditableFields();


var length = fields.length;


if (fields != null) {


          for ( var inc = 0; inc <= length; inc++) {


                try {


                      if (fields[inc] != "" && g_form.getControl(fields[inc]) != null) {


      g_form.setMandatory(fields[inc],false);


                            g_form.setReadonly(fields[inc], true);


                      }


                } catch (ex) {


                      console.log("Error : " + ex);


                }


          }


    }


alert('you dont have access to this task');


}


Hi Alex,



I would recommend the ACL's approach in this case.