The CreatorCon Call for Content is officially open! Get started here.

Restrict Variable Formatter to be editable only for certain group for a catalog item

Appu2
Tera Contributor

Hi, I need help with restricting the Variable formatter for certain group for one of the Catalog Item. My requirement is to make the Variable Formatter to be editable only for certain members of the group for rest all others it shouldn't be editable. I need to achieve this via Catalog Client Script. After submitting the request, in the backend Variables should be only editable for certain group and others shouldn't be able to edit.

Any inputs here?

1 ACCEPTED SOLUTION

Follow the below steps.

1. Write display BR on req item table

Condition : item is "select catalog name"

HarishKM_0-1695982632989.png

 

Script:

g_scratchpad.grp = gs.getUser().isMemberOf('ACME Support'); // pass the group name
 
2. Write onload client script on req item table
if(g_scratchpad.grp)

{
  g_form.setVariablesReadOnly(true);

}
 
HarishKM_1-1695982691877.png

 

 

Result:

HarishKM_2-1695982719420.png

 

Regards
Harish

View solution in original post

8 REPLIES 8

Ratnakar7
Mega Sage

Hi @Appu2 ,

 

To restrict a variable formatter to be editable only for certain members of a group for a catalog item in ServiceNow, you can achieve this by using a Catalog Client Script. The script will need to check if the current user belongs to the specified group, and if they do, allow them to edit the variable; otherwise, restrict access.

Here's an example of how you can create such a Catalog Client Script:

  1. Navigate to "Service Catalog" > "Catalog Client Scripts" in your ServiceNow instance.

  2. Click on "New" to create a new Catalog Client Script.

  3. Provide a suitable name and description for your script.

  4. In the "Script" field, you can use JavaScript to restrict variable editing based on the user's group membership.

 

Here's an example script:

(function () {
    // Define the group name that is allowed to edit the variable
    var allowedGroup = 'YourGroupName'; // Replace with your group name

    // Check if the current user is a member of the allowed group
    var user = gs.getUser();
    if (!user.isMemberOf(allowedGroup)) {
        // If not a member, disable the variable for editing
        g_form.setReadOnly('variable_name', true); // Replace 'variable_name' with the actual variable name
    }
})();

 

Thanks,

Ratnakar

 

Appu2
Tera Contributor

"gs" will not work in Client Script. 

Any other solution for this?

on which table you want to set variable editor readonly?

Regards
Harish

Appu2
Tera Contributor

sc_req_item table in which for only specific Catalog Item