Cancel request if catalog task is cancelled
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 04:23 AM
Hi Experts,
I have created a UI Action cancel task on catalog task form. So when "Cancel Task" UI action is clicked the associated RITM stage must be Request Cancelled, workflow must be cancelled and All associated REQ/RITM/Catalog task state must be closed incomplete. To achieve this I have written below script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2024 03:57 AM
Hi Radhika,
Thank you for response.
I used the above script.
SCTASK state is now close incomplete
RITM stage is request cancelled.
RITM state is close incomplete
but REQ state is close complete I need REQ state as close incomplete as well.
Please advice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2024 10:23 AM
Hi @Ankita Gupte Try below code
function cancelTask() {
if (confirm('Are you sure you want to cancel your Request?')) {
// Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_sc_task');
}
return false;
}
function updateTaskAndRITM() {
// Update current sc_task record (assuming this is the current task being cancelled)
current.state = 4; // '4' represents Cancelled state
current.work_notes = 'Request Cancelled';
current.comments = 'Request Cancelled';
current.update();
// Update related sc_req_item (RITM)
var reqItem = new GlideRecord('sc_req_item');
reqItem.addQuery('sys_id', current.request_item);
reqItem.query();
while (reqItem.next()) {
reqItem.stage = 'request_cancelled'; // Update to the appropriate stage name
reqItem.state = 4; // '4' represents Completed state
reqItem.active = false;
reqItem.update();
}
// Cancel workflows associated with the RITM (if needed)
new Workflow().cancel(reqItem);
// Update associated sc_request (REQ)
var req = new GlideRecord('sc_request');
req.addQuery('request_item', current.request_item);
req.query();
while (req.next()) {
req.state = 4; // '4' Cancelled state
req.work_notes = 'Request Cancelled';
req.update();
}
var catalogTask = new GlideRecord('sc_task');
catalogTask.addQuery('request_item', current.request_item);
catalogTask.query();
while (catalogTask.next()) {
catalogTask.state = 4; // '4' Cancelled state
catalogTask.work_notes = 'Request Cancelled';
catalogTask.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 05:25 AM
This is not working.
The RITM stage not getting updated and REQ state as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2024 07:37 PM
Hi Ankita,
thanks for the response
Again I checked the same code, I am getting the output REQ state is Close Incomplete. can you check the backend value for the REQ state ( for me the the REQ state field value is " closed_incomplete").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 05:26 AM
Hi Radhika,
For me also REQ state field value is " closed_incomplete" but not sure why it is not working for me.
the req state is still close complete.