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
07-01-2024 08:50 AM
Hi Ankita,
Oh really I am also confused why it notworking for you. It showing fine for me" close_incomplete".
my suggestion is check one more time the field name and the backend value for the REQ form state field.
Thanks
Radhika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2024 03:02 AM
Hi Radhika,
Request state value is close incomplete only, but still not working for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2024 03:19 AM
Can you try below code,
function cancelTask() {
g_form.setValue('state', 4);
gsftSubmit(null, g_form.getFormElement(), 'cancel_sc_task');
}
if (typeof window == 'undefined')
updateTask();
function updateTask() {
current.state = 4;
current.work_notes = 'Task Cancelled';
current.update();
// Close all catalog tasks associated with the RITM
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.request_item);
task.query();
while (task.next()) {
task.state = 4; // 4 is the state for 'Closed Incomplete'
task.update();
}
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.request_item)) {
ritm.stage = 'Request Cancelled';
ritm.state = 4; // 4 is the state for 'Closed Incomplete'
ritm.update();
}
// Cancel the workflow associated with the RITM
var wf = new Workflow();
wf.cancel(current.request_item);
// Close the associated REQ
var req = new GlideRecord('sc_request');
if (req.get(ritm.request)) {
req.request_state = 'closed_incomplete';
req.update();
}
// Redirect to the current record
action.setRedirectURL(current);
};
This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla