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 

gr.cat_item.name -> wrong.

gr.name ->right 

 

 

Please send me the screenshots of the Br or whatever you have written because you are writing it wrong.

Thanks

The issue is your if statement.

gr.request will get the sys_id of the request.
num is the number of the current record.

You'll never have a match between a number of a record and a sys_id.

Change var num = current.number to var reqID = current.getUniqueValue()
By doing this you get the sys_id of the current record and can compare it to another sys_id