Grab RITM variables and put them in SC task field

cfrazer
Giga Contributor

Hello,

I have a workflow that runs on the sc_request table and is used to order catalog items. It creates catalog tasks. I am trying to pull the information from the RITM item field from a request in order to populate in the task's short description so that the help desk team can see what items need to be ordered more easily. I want it to capture multiple items in the request so I used a glide query. I place this script in the Advanced section of the catalog task, but when I run the workflow the fields that should be populating are showing up as undefined. Can anyone help me out? Thank you!

Here is the RITM page. I want to take the item field and put it into my catalog task's short description.

Screenshot 2018-01-13 at 8.25.20 PM.png

Here's the code I'm trying to use:


var item = new GlideRecord('sc_req_item');

item.addQuery('request', current.sys_id);

item.query();

while(item.next()) {

var catalogItem = item.cat_item.getDisplayValue();

}    

var testing123 = task.short_description + catalogItem + ' X ' + item.quantity;

task.short_description = testing123;

Here's what happens when it runs (short description field shows undefined):

Screenshot 2018-01-13 at 8.24.23 PM.png

1 ACCEPTED SOLUTION

Lakshmaiah Dump
Giga Expert

Hi cfrazer,




It's seem to be you have used "request" instead of sys_id filed in addQuery();



I just changed request to sys_id in your code and ran(Background scripts) I got catalog item name.




var item = new GlideRecord('sc_req_item');


item.addQuery('sys_id', '30d7b6dbdba3430077377bedbf961963');


item.query();


while(item.next()) {


var catalogItem = item.cat_item.getDisplayValue();


gs.print("DLM :Cat item::"+catalogItem);


}




Check it out below out put.


cat_item.PNG



Hit Correct/ Endorsers/ Helpful/ Like depending on the impact of the response


Lakshmaiah Dumpala


View solution in original post

3 REPLIES 3

Lakshmaiah Dump
Giga Expert

Hi cfrazer,




It's seem to be you have used "request" instead of sys_id filed in addQuery();



I just changed request to sys_id in your code and ran(Background scripts) I got catalog item name.




var item = new GlideRecord('sc_req_item');


item.addQuery('sys_id', '30d7b6dbdba3430077377bedbf961963');


item.query();


while(item.next()) {


var catalogItem = item.cat_item.getDisplayValue();


gs.print("DLM :Cat item::"+catalogItem);


}




Check it out below out put.


cat_item.PNG



Hit Correct/ Endorsers/ Helpful/ Like depending on the impact of the response


Lakshmaiah Dumpala


Thank you for your help!!! That worked. I have another question for you please. When a person has multiple items in their request, it creates multiples catalog tasks for each item. Is there any way to put all the items bring ordered in one SC task?


You   can achieve the order of sc_task's in   workflow.