Cancel workflow script is not working in VA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have created one topic for open RITMS and given actions for cancel RITM for cancel i have write the below script in VA but not working state and comments updating fine but stage and workflow cancel not working
script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @siva44
Got it you’re cancelling an RITM from a Virtual Agent action.
Your script is updating some fields fine (state, comments) but stage + workflow cancel isn’t taking effect.
(function execute() {
var response = '';
var gr = new GlideRecordSecure(vaVars.table_name);
if (gr.get(vaVars.sys_id)) {
var comment = vaInputs.reason_for_request_cancel.getValue().trim();
if (comment) {
// Cancel workflows first
var wf = new global.Workflow();
wf.cancel(gr);
// Update RITM fields
gr.state = 4; // Closed Incomplete
gr.stage = 'request_cancelled'; // use internal value, not label
gr.approval = 'withdrawn';
gr.comments = "Cancelled by VA with comment: " + comment;
gr.active = false;
gr.update();
response = (vaVars.table_name == 'sc_req_item') ?
gs.getMessage("Requested item has been cancelled") :
gs.getMessage("OK, no comment will be added.");
} else {
response = gs.getMessage("No cancel comment provided.");
}
} else {
response = gs.getMessage("I couldn't find the record.");
}
return response;
})();
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/