How to pass variable values from catalog item to request table?

akriti2
Kilo Contributor

Hi all,

I have a basic question. I have a catalog item and   have created a variable called requested for(requested_for) on the catalog item. The value of this field needs to be passed to the requested for field(requested_for) on the request table (sc_request). How do I achieve this?

As you can see in the below screenshot, requested for value is Abel tutor in the catalog item form. I want this value to be passed to the request table instead of System Administrator. Please help.

Thanks & Regards,

Akriti

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Sorry, this script should be on sc_request table and change it from after to before business rule and put this script in there. You are good to go



var gr= new GlideRecord("sc_req_item");


  gr.addQuery('request',current.getValue("sys_id"));


  gr.addQuery("item.name","put your item name here");


  gr.query();


  if(gr.next()){


  current.requested_for=gr.variables.requested_for;


  }


View solution in original post

7 REPLIES 7

Abhinay Erra
Giga Sage

There is default value set on requested for to the logged in user. In order to change the requested for value on request, you can create an after business rule on sc_req_item table


When: after insert


Conditions: Item is <slect your item>


Script:



var gr= new GlideRecord("sc_request");


gr.get(current.getValue("request"));


gr.requested_for=current.variables.requested_for;


gr.update();


Thank a lot Abhinay. The business rule is able to populate the correct requested for value in both request and requested item form.   The   issue I am having now if that after submitting the order I get unique key violation message.  


find_real_file.png


Also due to this, for some reason the due date in request gets wiped out but appears in requested item


find_real_file.png


find_real_file.png


There are some Catalog items that do not have the requested for variable. For those cases the requested for field on the request form and requested item form is empty. Can you please suggest   how to go about this?



find_real_file.png


Sorry, this script should be on sc_request table and change it from after to before business rule and put this script in there. You are good to go



var gr= new GlideRecord("sc_req_item");


  gr.addQuery('request',current.getValue("sys_id"));


  gr.addQuery("item.name","put your item name here");


  gr.query();


  if(gr.next()){


  current.requested_for=gr.variables.requested_for;


  }


Perfect!! Thank you very much Abhinay!