- 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 03:04 PM
You're welcome! just FYI, can access a variable from the client side by using g_form.getValue('variables.variableName') (for example (g_form.getValue('variables.requested_for')); For reference field, you can use this g_form.getDisplayBox('request.requested_for').value. If you know the names of your variables you can then apply your logic as to when all variables should be readonly and when some needs to remain editable.
If you are feeling fancy, you could do a glideAjax calls to get the list of variables and grammatically set each of them readOnly or not.
These are just the options you can go about doing this, feel free to reach out if you need help with the coding side of things 🙂
Thanks,
Phuong
- 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);
}
}
}