- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi
We currently have an ACL where item names are hardcoded to make variables editable on the sc_task level. However, we now want to replace this hardcoding and use a system property (with either a comma-separated list or query) to determine which catalog items should have editable variables.
I tried the below script, but itās not working as expected. Could anyone please help me modify or correct it?
Script-
(function() {
// Read comma-separated sys_ids of catalog items from property
var editableItems = gs.getProperty('glide.sc_task.editable_variables', '').split(',');
// Clean and normalize
editableItems = editableItems.map(function(x) { return x.trim(); }).filter(Boolean);
// Get current catalog item's sys_id from the sc_task record
var itemSysId = current.item ? current.item.toString() : '';
// Allow edit only if current item's sys_id is listed in the property
return editableItems.indexOf(itemSysId) !== -1;
})();
System property-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
so none of the variables should be editable on catalog task form to any user for RITMs belonging to those Items?
If yes then 2 approaches
1) onLoad client script + display business rule on sc_task
Display BR
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var editableItems = gs.getProperty('glide.sc_task.editable_variables');
if (editableItems) {
var arr = editableItems.split(',');
var currentItem = current.request_item.cat_item.sys_id;
g_scratchpad.makeReadonly = !(arr.indexOf(currentItem) > -1); // I added not in the beginning
} else {
g_scratchpad.makeReadonly = false;
}
})(current, previous);
Normal onLoad Client Script and not catalog client script:
function onLoad() {
if (g_scratchpad.makeReadonly)
g_form.setVariablesReadOnly(true);
}
OR
2) ACL -> I am not sure if this works fine, you are already using this.
If the 2nd approach doesn't work or it takes time, 1st approach will work for sure.
š” If my response helped, please mark it as correct ā and close the thread šā this helps future readers find the solution faster! š
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
try below:
answer= false;
var editableItems = gs.getProperty('glide.sc_task.editable_variables');
var currItem = current.request_item.cat_item.sys_id;
if(currItem.indexOf(editableItems)>-1)
answer true;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @RaghavSh
Tried this but not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Try this, I believe the if stetment checking indexOf need to be reversed:
answer= false;
var editableItems = gs.getProperty('glide.sc_task.editable_variables');
var currItem = current.request_item.cat_item.sys_id;
if(editableItems.indexOf(currItem)>-1)
answer true;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@RaghavSh Thanks for the reply.
Still not working. Tried using both ways.
