How to get catalog variable values in business rule ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:03 PM
Hi,
How to fetch catalog variable value in an after business rule.
I tried --> current.variables.<variable_name> but not working correctly.
Thanks,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 11:59 AM
Hi Allen,
The requirement is that, when I submit a catalog item say catalogA, the BR should consider one particular variable value from that RITM - Yes or No value - if the value is 'No', then the BR should submit a new request this time for catalogB. Also, the variable value from catalogA should be updated in catalogB variable as well.
I have written an after insert BR. Below is the script I am using:
(function executeRule(current, previous /*null when async*/ ) {
gs.log("Form field value is: " + current.u_requested_foor); // This is displayed
gs.log("Variable editor variable value is: " + current.variables.user_name); // This is shown as undefined
var cart = new Cart();
var item = cart.addItem('6ad1a41cdb7d22406ba15aa9bf9619a0');
cart.setVariable(item, 'requested_for', current.requested_for);
cart.setVariable(item, 'token_options', 'software_token');
var cartGR = cart.getCart();
cartGR.requested_for = current.variables.user_name;
cartGR.update();
var newSerReq = cart.placeOrder();
//newSerReq.opened_by = current.caller_id;
newSerReq.update();
current.correlation_id = getRITM(newSerReq.sys_id);
current.update();
function getRITM(serReq) {
var ritm = '';
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', serReq);
grRITM.query();
if (grRITM.next()) {
ritm = grRITM.sys_id;
}
return ritm;
}
})(current, previous);
Please let me know if you need more information.
Thanks,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 12:51 PM
Gopi ,
what are your trigger conditions for your BR?
and are you sure in this line the field name is u_requested_foor? or its a typo error which should be u_requested_for ?
Reason behind checking this is even if a field name is incorrect it might stop the execution of the script at that line .
also share your br TRIGGER CONDITiONS and is it a after insert or update BR ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:05 PM
helllo gopi,
usually this is the correct syntax that you followed
current.variables.your variable name
but better check your variable name properly
and also can you share your script ?lets debug
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 01:21 PM
Hi Mohith,
I am putting 2 log statements as below and only the first one works.
gs.log("Form field value is: "+current.u_requested_foor); // this is the requested for field on the RITM form
gs.log("Variable editor variable value is: "+current.variables.user_name); // this is the user name variable in variable editor in the same RITM form
Thanks,
Gopi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 06:28 AM
Ideally, above should work. Are you sure the RITM you checking log for has user_name variable used?