Copying a variable from one RITM to another

turnea
Mega Expert

Has anyone got a script that will copy a variable from one RITM to another within the same REQ?   I have a catalog item that is primary (PRF), then you can add several secondary items (Additional PRF).   There's a section where the team leads assign an IT Engineer (it_engineer) to being the request to completion, but it occurred to me that the IT Engineer needs to be automatically added to the other RITMs.   Any idea how we can accomplish this?

Thank you,

Amandah

1 ACCEPTED SOLUTION

Hi Amandah,



Here is the updated code. Please go through it. In this case execute business rule only when the catalog item is primary catalog item. How we do that?


Yes this is simple all you need to do is under "When to run" select the filter condtition as item.name is the item name.


Screen Shot 2015-09-17 at 7.05.38 PM.JPG


Script :


var gr = new GlideRecord('sc_req_item');  


gr.addQuery('request', current.request);  


gr.addQuery('cat_item_name', 'Additional PRF');     //Assuming Additional PRF is the catalog item name


gr.query();  


while(gr.next())  


{  


gr.variables.it_engineer = current.variables.it_engineer;


gr.update();  


}  


View solution in original post

8 REPLIES 8

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Amandah,



You can fetch the value of the catalog variables at the business rules as current.variables.caller; //Here caller is the name of the variable


You can GlideRecord the appropriate RITM and then push the value.



Please let me know if you have any questions.


I have no experience with this type of business rule.   Can you help me out at all with a basic code?


Hi Amandah,



Here you go.


var item = current.cat_item.name = 'Access'; //Replace Access with the exact item name you want to update


var gr = new GlideRecord('sc_req_item');


gr.addQuery('request', current.request);


gr.addQuery('cat_item_name', item);


gr.query();


while(gr.next())


{


gr.variables.caller = current.variables.stat; //Here replace caller with the target variable name and replace stat with the current variable name of which you want to copy.


gr.update();


}


Hi Pradeep,



The variable names are the same (it_engineer) but the two catalog items are different.   The variable will need to be pulled from the primary catalog item (PRF) and applied to all secondary items (Additional PRF) if any.   I'm not sure that the code reflects that, or am I missing something?