The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to allow only certain users access to RITM variables

magoo
Kilo Expert

Hello all,

Currently I have a client script that makes it so users are unable to change variables at the RITM level.   What I am looking to do is add a list (u_users_with_access) on my catalog item that references the user table which would allow me to list certain users that should have rights to modify the data on that RITM.   Any help would be appreciated.

My current client script is the following;

Table: Requested Item

Type: onLoad

function onLoad(){

  $(variable_map).select("item").each(function (elmt)

  {

  try {

  g_form.setDisabled('variables.' + elmt.getAttribute('qname'),true);

  }

  catch (err)

  {

  }

  }

  );

}

1 ACCEPTED SOLUTION

ohhgr
Kilo Sage
Kilo Sage

Hi Steven,



I think you could check if the user is a part of the list using a display business rule and then set the value in a scratchpad variable.



so, your display business rule would be like



g_scratchpad.restrict_edit = true;


if(current.cat_item.u_users_with_access.toString().indexOf(gs.getUserID()) != -1) {


g_scratchpad.restrict_edit = false;


}



In your script above, just add below check



if(g_scratchpad.restrict_edit) {


$(variable_map).select("item").each(function (elmt)


  {


  try {


  g_form.setDisabled('variables.' + elmt.getAttribute('qname'),true);


  }


  catch (err)



  {


  }


  }


  );


}



Hope that helps.


Mandar


View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Steven,



You can add an if condition to the existing client script to restrict it based on users/roles. Please let me know if you have any questions.


Please check section 3.3 for ex.


GlideUser (g user) - ServiceNow Wiki


Ken83
Mega Guru

I was thinking it'd be easier to do it using ACLs but i actually can't think of a way to utilize ACLs to restrict access to variables. So, maybe you can create a role for that functionality and in your script just utilize the g_user.hasRole() method to check and go from there.


ohhgr
Kilo Sage
Kilo Sage

Hi Steven,



I think you could check if the user is a part of the list using a display business rule and then set the value in a scratchpad variable.



so, your display business rule would be like



g_scratchpad.restrict_edit = true;


if(current.cat_item.u_users_with_access.toString().indexOf(gs.getUserID()) != -1) {


g_scratchpad.restrict_edit = false;


}



In your script above, just add below check



if(g_scratchpad.restrict_edit) {


$(variable_map).select("item").each(function (elmt)


  {


  try {


  g_form.setDisabled('variables.' + elmt.getAttribute('qname'),true);


  }


  catch (err)



  {


  }


  }


  );


}



Hope that helps.


Mandar


Thanks Mandar!   That worked perfectly!