- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 05:57 AM
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)
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 08:32 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 09:01 AM
Glad that you got this resolved. Don't forget to mark it as answered.
Thanks,
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 06:10 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 06:15 AM
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