Restrict closing sctask from the list view only for 1 catalog item
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have created an on celledit client script to restrict sctask to close from list view
but I cannot make it catalog item specific, It is working globally.
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var closedStates = ['3', '4', '7'];
//Type appropriate comment here, and begin script below
var gr = new GlideRecord('sc_task');
gr.addQuery('cat_item', 'a02b27ab3b033210a546bffe23e45a8e');
gr.query();
while (gr.next()) {
var reqItem = gr.cat_item;
}
// "a02b27ab3b033210a546bffe23e45a8e" is sys_id of catalog item
if (reqItem == 'a02b27ab3b033210a546bffe23e45a8e') {
if (closedStates.indexOf(newValue) > -1) {
alert("You cannot close a Task from the list view. Please open the Task record to close.");
saveAndClose = false; // prevents closure of sctask on list view
}
}
callback(saveAndClose);
}
for every catalog it is working or it is not working pleas help me in this
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @payalnkunte
Create a List Edit ACL on sc_task:
- Navigate to ACLs: Go to System Security > Access Control (ACL) and click New.
- Set up the ACL:
- Type:
list_edit - Operation:
write - Name:
sc_tasktable, specifically thestatefield (sc_task.state).
- Type:
- Define the Condition:
- Add a condition to target the specific catalog item:
Request Item.Item|is|[Select your Catalog Item]
- Add a condition to target the specific catalog item:
- Define the Script:
- Check "Advanced" and use the script below to prevent the update:
// Allow admins to override if (gs.hasRole('admin')) { answer = true; } else { // Prevent changing state to Closed Complete ( 3 )or Closed Incomplete (4 ) if (newValue == '3' || newValue == '4') { answer = false; gs.addErrorMessage('Cannot close this specific catalog task from the list view.'); } else { answer = true; } }
- Check "Advanced" and use the script below to prevent the update:
- Save the ACL
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
59m ago
There's a logical mistake in your script and also Do not use GlideRecord in client scripts. You can try approach shared by @Tanushree Maiti which will work server side also.
Regards,
Sumanth
