How to Make future catalog task & RITM read-only after 2nd catalog task in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Dear Community,
I have a catalog item , after submission of this , it generates total 5 catalog tasks, what i want is when the 2nd task short description of task " Agreed date completed" is closed, i want to make future catalog tasks and RITMs variables read only.
I have tried this through UI policy and catalog client script but its not working. Any guidance would be really helpful!
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
@Naresh_5120 May I know the use case here for making the tasks readable? Ideally, this can be achieved via a combination of catalog client script having a GlideAjax call to a client callable script include which should check the status of the 2nd task and return true/false to make fields editable/read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Business case is there is 2nd task called "agreed date " after completion of this task, business want to stop further modification in future catalog and RITMS variables (fields)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
@Naresh_5120 As suggested earlier, please try the combination of GlideAjax + client callable script include. Based on the response receive from Server. Make all the fields read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
you can use onLoad catalog client script + GlideAjax which runs on sc_task and sc_req_item
that will check if the 2nd task is closed or not
Script Include: It should be client callable
var YourScriptIncludeName = Class.create();
YourScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkPreviousTaskClosed: function() {
var recordId = this.getParameter('sysparm_record_id');
var table = this.getParameter('sysparm_table');
var parent = null;
// Determine parent (RITM) based on table
if (table === 'sc_req_item') {
parent = recordId;
} else if (table === 'sc_task') {
var task = new GlideRecord('sc_task');
if (task.get(recordId)) {
parent = task.request_item;
} else {
return 'false';
}
} else {
return 'false';
}
// Get all tasks for the parent and check if the previous "Agreed date completed" task is closed
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item', parent);
tasks.orderBy('sys_created_on');
tasks.query();
var foundCurrent = false;
while (tasks.next()) {
if (table === 'sc_task' && tasks.sys_id == recordId) {
foundCurrent = true;
continue;
}
if (!foundCurrent) {
if (tasks.short_description == 'Agreed date completed' && tasks.state == '3') {
return 'true';
}
}
}
return 'false';
},
type: 'YourScriptIncludeName'
});
onLoad Catalog Client Script: Which Applies on Applies on Catalog Tasks = True and Applies on Requested Items = True
function onLoad() {
var table = g_form.getTableName();
var recordId = g_form.getUniqueValue();
var ga = new GlideAjax('YourScriptIncludeName');
ga.addParam('sysparm_name', 'checkPreviousTaskClosed');
ga.addParam('sysparm_record_id', recordId);
ga.addParam('sysparm_table', table);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer === 'true') {
g_form.setVariablesReadOnly(true);
}
});
}
💡 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