Getting Value from variable and Updating to Form field in Requested Item table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2019 07:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2019 03:30 AM
Hi Vishal/kirankumarv11,
Just to inform you that below business rule works fine in insert case.When item is ordered from service catalog it generates a record in request and in requested Item table here I have applied below before business rule on sc_request in this case variable requested for data is populated in Requested Item with out any issue.
(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;
}
}
})(current, previous);
Now when I update Requested Item form this Requested For value is getting empty.So i have written same business rule on sc_req_item table before update above business rule should execute and it should update value from variable to a form field.I have tried all the possible ways and also what you both suggested but still its not working.
Thanks,
Lokesh.