How to get the catalog task number associated with a requested item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2017 03:45 AM
for my requested item a catalog task is generated . I want to get the the task number which is present in in related list in my requested item form.How can i get it using background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2017 04:26 AM
Correct me if I a wrong,Do you want to get the RITM sys_id from the GlideRecord. If it is yes below is the code the setting the limit for first 5 records.
var ritm=new GlideRecord('sc_req_item');
ritm.setLimit(5);
ritm.query();
while(ritm.next()){
var gr=new GlideRecord('sc_task');
gr.addQuery('request_item',ritm.sys_id);//provide the ritm sys_id
gr.query();
while(gr.next())
{
var res=gr.number+','+res;
}
gs.log(ritm.number+'-'+res);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2017 04:32 AM
define the variable res above the loop
instead of below lines
while(gr.next())
{
var res=gr.number+','+res;
}
use this
var res = '';
while(gr.next())
{
res =gr.number+','+res;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2017 04:02 AM
The problem is there isn't "THE". sc_task has a many-to-one relationship with sc_req_item. Via background script you can get ALL of a Requested Item's child SC_Tasks by...
var rotiserie_chicken = (whatever the sys_id of your requested item);
var prostetnic_vogon_jeltz = new GlideRecord('sc_task');
prostetnic_vogon_jeltz.addQuery('parent', rotiserie_chicken);
prostetnic_vogon_jeltz.query();
while (prostetnic_vogon_jeltz.next())
gs.print(prostetnic_vogon_jeltz.number + " - " + prostetnic_vogon_jeltz.short_description);
}
gs.print("Remember to like and mark correct!");
gs.print("Chuck Tomassi is the king");
Fun fact: An sc_task populates both the request_item and parent fields with the RITM's sys_id. I use Parent just for consistency across the platform.