When RITM is read-only, how to allow a role or group to edit?

yvonnew
Kilo Guru

We have a Business Rule which locks down all RITMs so that the variables cannot be edited. We now have a requirement for a certain role to be able to unlock variables on a particular catalog item. Is anyone able to point me in the direction of a solution please?

The Business Rule runs on the sc_item_options table

When to run:

Before Update

Updated by is not system

Condition:

current.value.changes()&&current.value != previous.value

Script:

gs.addInfoMessage('You are not allowed to change any information on this form once submitted.');

current.setAbortAction(true);

abort_on_variable_change.JPG

1 ACCEPTED SOLUTION

ark6
Mega Guru

Not the right way though to disable variables.



However, with your current design you can do this.



if(!gs.hasRole('custom_role')//custom_role this is the role which will have access to variables


{


gs.addErrorMessage('You are not allowed');


current.setAbortAction(true);


}



However, have a look at the below for disabling vaiables



Check below for different ways to disable a variable, I personally like the client script one.



https://www.servicenowguru.com/scripting/business-rules-scripting/variables-form-readonly/


View solution in original post

6 REPLIES 6

leebooth
Kilo Expert

You can put a check in your script, using the getUser & hasRole functions:



if (!gs.getUser().hasRole('your role name')) {


  gs.addInfoMessage('You are not allowed to change any information on this form once submitted.');


  current.setAbortAction(true);


}



This means when the business rule is triggered - the code you have, which outputs a message and aborts the current action, will only run if the current user doesn't have the specified role. Otherwise, nothing happens.


Thanks for your reply.



We want to allow the role to edit the variables on only one catalog item, not them all. Can we do this?


Okay modify it to


if(!gs.hasRole('custom_role') && current.item_option_new.cat_item=='<sys_id of the cat item>'




OR




if(!gs.hasRole('custom_role') && current.item_option_new.cat_item.getDisplayValue=='<name of the item>'


This was the correct answer.



I see that this field had been edited from 'current.questions.cat_item' to 'current.item_option_new.cat_item' which resolved my issue.



Thanks.