How to get the catalog task number and task sys_id within the Workflow Activity creating the task?

Khalid5
Tera Expert

I have a use case, where I need to fetch the task number and task sys_id at create task workflow step to send these values to REST Message - POST method.

Any suggestion how I can get these values at the create task workflow step ?

I have created this workflow for a service catalog item and after approval stage I am creating a fulfillment task.

Any clue to get this done would be appreciated.

Regards,

Khalid

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Khalid,

task sys_id can be obtained in the catalog task advanced activity using this

task.setNewGuid();

for getting task number workaround here

https://community.servicenow.com/community?id=community_question&sys_id=618f347ddbeca450b1b102d5ca96...

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Anil Lande
Kilo Patron

Hi Khalid,

You can user GlideRecord query to get sys_id and numbe of thask you have created for your RITM.

var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item',current.sys_id);
taskGR.addQuery('short_description','Your task short description'); //additional filter condition to get your task record
taskGR.query();
if(taskGR.next()){
//get required values from taskGR.fieldname
}

 

Please mark correct answer and helpful if this help to resolve your issue.

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Khalid,

Also an alternative to get the task sys_id and number in same activity is to create a catalog task using "Run Script" activity instead "Create Catalog Task" activity.

In run script activity you can use Glide Record API to insert task and once task is created you get the sys_id of same record as return value. In same script you can Glide to sc_task table to get record using sys_id and get all other parameters.

Also in same script you can call REST API's.

 

Thanks,

Anil Lande 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

I already tried to fetch the required values using the Glide Record API in Create Catalog Task activity -> Advanced script but no luck.

Used the following script:

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item.number',current.number);
gr.query();
gr.next();
var task_number = gr.number;
var task_sysid = gr.sys_id;

Regards,

Khalid

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Khalid,

task sys_id can be obtained in the catalog task advanced activity using this

task.setNewGuid();

for getting task number workaround here

https://community.servicenow.com/community?id=community_question&sys_id=618f347ddbeca450b1b102d5ca96...

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader