Cancel workflow script is not working in VA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2025 05:12 AM
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
09-11-2025 01:08 AM
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;
})();