Getting Value from variable and Updating to Form field in Requested Item table

lvakare
Kilo Contributor

Hi All,

I have a case where I need to get the value from the variable(i.e.,requestedFor) and Update to a form field(sc_req_item.request.requested_for). Both variable and Form are part of Requested Item table. I want to Update this value before updating the value to a database. So I was trying with a before business rule on "sc_req_item" table. Below is the business rule I am using but no luck.Value is not getting updated.

(function executeRule(current, previous /*null when async*/) {


var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.sys_id);
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) {

current.requested_for = grRITM.variables.requested_for;
}
}

}

 

I have seen in the community that I cannot use variables on the client script. We need a script include to do so. How can I achieve my requirement either with client script or business rule?

 

Below is the screenshot attached of variable and form field.

 

5 REPLIES 5

kirankumarv11
Mega Expert

Hi Ivakare,

Is your before business rule executing?

If yes, pls try current.request_for = current.variables.requested_for;

I hope this will work for you.

lvakare
Kilo Contributor

Hi kirankumarv11,

 

Thanks for the reply. You are right my business rule is not executing don't know why it's not executing. Any idea on why it's not running?

Even I tried with updating current.request_for = current.variables.requested_for; but still requested for in form field is blank. Because my business rule is not executing.

 

Thanks,

Lokesh.

Hi Lokesh,

I believe, for this catalog item you have created one workflow. In workflow, by using run script you can achieve this. In run script add the below code: 

current.request_for = current.variables.requested_for;

Current.update();

 

 

Regards

Kiran

Vishal Khandve
Kilo Sage

Hi,

add condition of catalog item for which you want to run this  and use below code

 

current.requested_for = current.variables.varaible_name;

current.update();

 

Thanks,

Vishal