How to populate custom field on Request table with value from Requested Item table?

jaredholm
Kilo Contributor

I would like to populate a custom string field (could be changed to a reference field if that is more appropriate?) called "u_catalog_item" I have created on the Request (sc_request) table with the value of the Item (cat_item) field on the Requested Items (sc_req_items) table. I need to filter REQs based on the Catalog Item from which they were created. For example, I have a catalog item "Request to Pull Email". The only place the name of this catalog item appears is on the RITM table. So, I have to populate the field on the REQ table with the "name" value on the RITM table. This requires matching the records based on REQ### and then populating the custom field. I have created a business rule to automatically populate the custom field, but am getting stuck on the GlideRecord query to grab the Request numbers and match them to copy the name data. I currently have an after Insert or Update BR that has a script that looks like this:

     var cat_item = current.u_catalog_item;
     var gs = new GlideRecord('sc_req_item');
     gs.addQuery('request');
     gs.query();
     while (request == sc_request.request){
          cat_item = sc_req_item.name;
     }

Can somebody please tell me what is wrong with this script? Much appreciated

15 REPLIES 15

Hi 

so do when you are saying name what exactly do you want to populate? Because there is no name feild available . Or do you want the display value to RITM ?

I want the display value of the Item field on the RITM table because this is the name of the catalog item that I need to populate my custom field.

To get the display value use this

gr.getDisplayValue('cat_item');

Script should be something like this

var reqID = current.getUniqueValue()
 
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', reqID);
gr.query();
if (gr.next()){
   current.setValue('u_catalog_item', gr.getDisplayValue('cat_item'));
}

jaredholm
Kilo Contributor

I changed the code to what you have above, the update topped off at 300 seconds and did not complete. Not sure where to go from here.