Get sys_id task from request item

rapbriqu
Kilo Expert

Hi community,

I need to get the sys_ID task from a new request item. Can you help me please

(The task is create by a workflow)

find_real_file.png

Thanks

1 ACCEPTED SOLUTION

You are getting the request sys_id not requested item. Here is your updated script. Try this



gs.include('Cart');


var cart= new global.Cart();


var item=cart.addItem('put in the sys_id of catalog item');


var rc= cart.placeOrder();


var reqID=rc.getValue('sys_id');


var body={};


var scTaskID='';


var scTask= new GlideRecord('sc_task');


scTask.addQuery('request',reqID);


scTask.query();


while(scTask.next()){


if(scTaskID.length >0){


scTaskID+=scTask.getValue('sys_id')+',';


}


else{


scTaskID=scTask.getValue('sys_id');


}


}


body.name=scTaskID;


}




Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

7 REPLIES 7

Glad that you got this resolved. Don't forget to mark it as answered.



Thanks,


Abhinay


rehani
Tera Contributor

Hi,



The rc variable will be the Request record.   You can use this to search against the sc_req_item table using a GlideRecord and look for a record where the request is equal to the rc.sys_id value (in your case the reqItemID value).



I would add a condition to make sure you don't do the GlideReecord search if the reqItemID is null/empty and instead log an error.


paramveer
Mega Guru

if you put a log on reqItemID , you will definitely see the sys_id.



rc.sys_id will definitely give the correct sys_id of task.




~Paramveer Singh


~ServiceNow Developer



~Please mark Helpful, Like, or Correct Answer if applicable