- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 06:33 AM
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()&¤t.value != previous.value
Script:
gs.addInfoMessage('You are not allowed to change any information on this form once submitted.');
current.setAbortAction(true);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 06:46 AM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 06:42 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 06:44 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 06:51 AM
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>'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2017 08:38 AM
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.