Can I pass a variable from a requested item to the approval?

cmills_1128
Kilo Contributor

Could I achieve this with a client script?   I created a string field on the approval form, but I need to figure out how to pass the text from the request to the approval form.

The variable on the item is a single line text variable named bms_program_name

The field on the approval is a string field named u_bms_program_name

1 ACCEPTED SOLUTION

Cynthia,



I have skimmed through your comments and noticed that you have only checked insert check-box on the business rule. You will have to check the update check-box too and add this script. It should work now



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



var app = new GlideRecord('sysapproval_approver');


app.addQuery('sysapproval', current.sys_id);


app.query();



while (app.next()) {


        app.u_bms_program_name = current.variables.bms_program_name;


        app.update();


}


})(current, previous);




Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

10 REPLIES 10

Chuck Tomasi
Tera Patron

Hi Cynthia,



I would do this with an after business rule on the sc_req_item (requested item) table.



After the request item moves to approval state (or whatever state you use to wait for approval, or perhaps the approval field is set to requested), it triggers the business rule to lookup any related approvals and update the field with the value from the variable. The key is something like:



var app = new GlideRecord('sysapproval_approver');


app.addQuery('approval_for', current.sys_id);


app.query();



while (app.next()) {


        app.u_bms_program_name = current.variables.bms_program_name;


        app.update();


}



You'll want to ensure that your business rule condition filters on the proper request items as I don't suspect that variable is going to be on all of them so it can skip the ones that don't.


Hi Chuck,



I created the after business rule and added the filter conditions to look for the specific items and the stage is "Legal Approval", which is the stage and approval I'm looking to add the client name to.   It's not filling in the client program name as expected.



I checked the box next to insert.



Java script isn't my strong suit.   There was some pre-populated script in the advanced script field.   Here's the script:



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





var app = new GlideRecord('sysapproval_approver');


app.addQuery('approval_for', current.sys_id);


app.query();



while (app.next()) {


        app.u_bms_program_name = current.variables.bms_program_name;


        app.update();


}


})(current, previous);


Cynthia,



It should be sysapproval in the addQuery() as shown below.


Change this line"app.addQuery('approval_for', current.sys_id);" to "app.addQuery('sysapproval', current.sys_id);"



Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


Hi Adhinay,



I updated the script and see no change in the approval record.



Best,


Cynthia