- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 12:04 PM
We have the "Write roles" field defaulted to "admin" for catalog item variables to prevent end users from being able to change the variable values of RITMs, TASKs, INCs, etc.
What I have noticed is that these write roles also apply to the "SC Edit Item" Service Portal page, which is rendered using the "sp-variable-editor" widget.
We don't want the variables seen from the shopping cart (when the user clicks the pencil edit icon) to be read-only to the end users. We want the end users to be able to change these variable values before the complete their cart checkouts.
I have played around with the widget and ACLs and I can't seem to get this to be the case.
Any input would be greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2019 09:20 AM
I have done a work-around to accomplish the task of allowing users to edit their items in their Service Portal shopping carts while also keeping the catalog variables read-only (conditionally) on the RITM and TASK forms.
Essentially, the catalog variables associated with the RITM or TASK that do not have any write roles applied are placed in a scratchpad from a business rule, which is then referenced in the client script to make read-only on the form. This way, catalog variables that have conditional write roles are not forced read-only on the forms.
Below are the steps that I have taken and have determined the proof of concept:
- I have removed the "admin" write roles from all variables that users need to be able to edit from their Service Portal shopping carts.
- I have created the following business rules:
Name: RITM Variable Scratchpad
Table: sc_req_item
When: display
Script:
(function executeRule(current, previous /*null when async*/) {
var ritmVars = [];
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', current.sys_id);
gr.query();
while (gr.next()) {
var writeRole = gr.sc_item_option.item_option_new.write_roles;
if (JSUtil.nil(writeRole)) {
var variableName = gr.sc_item_option.item_option_new.name.toString();
ritmVars.push(variableName);
}
}
g_scratchpad.ritmVars = ritmVars;
})(current, previous);
Name: TASK Variable Scratchpad
Table: sc_task
When: display
Script:
(function executeRule(current, previous /*null when async*/) {
var taskVars = [];
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', current.request_item);
gr.query();
while (gr.next()) {
var writeRole = gr.sc_item_option.item_option_new.write_roles;
if (JSUtil.nil(writeRole)) {
var variableName = gr.sc_item_option.item_option_new.name.toString();
taskVars.push(variableName);
}
}
g_scratchpad.taskVars = taskVars;
})(current, previous);
- I have activated the following OOB client scripts and modified them:
Name: Variable Editor Readonly
Table: sc_req_item
UI Type: Desktop
Type: onLoad
Script:
function onLoad() {
if (g_scratchpad.ritmVars != '') {
var ritmVars = g_scratchpad.ritmVars;
for(i = 0; i < ritmVars.length; i++){
g_form.setReadOnly('variables.' + ritmVars[i], true);
}
}
}
Name: Variable Editor Readonly
Table: sc_task
UI Type: Desktop
Type: onLoad
Script:
function onLoad() {
if(g_scratchpad.ritmVars != ''){
var taskVars = g_scratchpad.taskVars;
for(i = 0; i < taskVars.length; i++){
g_form.setReadOnly('variables.' + taskVars[i], true);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 12:28 PM
Hi m.osborne,
If your goal is to prevent the end user from being able to edit variables in RITMs, SCTASKs, etc... You might be better of adding the "readonly_variable_editor": "true" to the Quick start config of the Service Portal record.
Thanks,
Phuong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 12:53 PM
I have "readonly_variable_editor": "false" in Quick start config for the Service Portal, since I want the variables to be editable by end users in the shopping cart, but having "admin" in the "Write roles" field of the catalog item variable seems to completely overwrite this.
I am trying to have the variables both read-only on platform-side RITMs, TASKs, INCs, etc and editable in the Service Portal shopping cart.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 01:29 PM
There are two Out-Of-Box client scripts on RITM and SCTASK tables that set the variables to read only in the platform side, you just need to make them active, the name is "Variable Editor Readonly": https://<instance>.service-now.com/sys_script_client_list.do?sysparm_query=nameSTARTSWITHVariable%20edit%5EORDERBYDESCsys_updated_on&sysparm_list_mode=grid
Activating them will achieve your goal on the platform side of things, then if you remove the write role that should take care of things on the Service Portal side, does that achieve your goal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 02:36 PM
While these client scripts are great, we do have special cases where a variable would be mandatory and editable on a TASK or RITM and needs a value to progress the workflow.
These client scripts would work, but it would require a bit of overhead and hard-coding to accommodate those special-case variables that need to remain editable. I also have a HI ticket open so I will keep this idea in mind while we wait for their response.
Thank you so much for responding! I will update this thread with any new information.