Close Catalog task automatically from workflow servicenow

Revathi12
Tera Contributor

Hi,

We have a requirement where we need to close the task from workflow in servicenow. I have tried using below script but its not working.

 

var sysID = current.sys_id;
var ctask = new GlideRecord('sc_task');
    ctask.addQuery('number',sysID);
    ctask.query();
    while(ctask.next()){
        current.state = '3';
        current.active = 'false';
        current.description = "Autoclose task";
        current.update;
}
3 REPLIES 3

Mark Manders
Mega Patron

The 'number' of your task isn't the sys_id of the current task, I assume? Depending on which table the flow is running, you will need to look for the reference field containing that variable (sysID).


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders :- Number is the field in the catalog task and flow is running on request item table

ctask.addQuery('number',request_item); // request_item is the reference field in catalog task table. Is that correct?

What? 

You need the field that holds the sys_id of the requested item. How is that ever the number field of the catalog task? Assuming you are OOB:

 

ctask.addQuery('request_item',sysID);

 

And also check your update, because updating the description with 'auto close task' will override the content of that field. Why not update the worknotes with this update?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark