How to access the sys id of the catalog item variables throgh business rule

sai29
Tera Contributor

I have a catalog item where RITM Number of other requests is present in the catalog variables of that Item. I need to get the sys id of the ritm number from the catalog variables present in the Catalog Item. I have tried to do it using the business rule(after BR) But not getting it. However through the background script I am able to get the sys_id of RITM Number.

Background Script below which is working fine

 var gr = new GlideRecord("sc_task");
gr.addQuery('request_item',"e915e6fc1b0c5110c9fd1fc3b24bcb1b");
gr.query();
if (gr.next()) {
gs.log("inside first if");
var appr = gr.variables.ritm_number;
gs.log(appr);
if (appr) {
gs.log("inside second if");nd
var approver = new GlideRecord("sysapproval_approver");
approver.addQuery('sysapproval', appr);
approver.query();
if (approver.next()) {
gs.log("inside first2 if");
approver.state = 3;
approver.update();
}
}
Before BR
(function executeRule(current, previous /*null when async*/ ) {
gs.log("test");
// Add your code here
var appr = current.variables.ritm_number.toString();
gs.log("siva",current.variables.ritm_number);
gs.log(appr);
if (appr) {
gs.log("inside second if");
var approver = new GlideRecord("sysapproval_approver");
approver.addQuery('sysapproval', appr);
approver.query();
if (approver.next()) {
gs.log("inside first2 if");
approver.state = "approved";
approver.update();
}
}

})(current, previous);
1 REPLY 1

Brian Lancaster
Tera Sage

I'm note 100% sure I'm understand your question based on the code you provided. Nowhere in you BR are you trying to get the sys_id and in your background script you have hard coded the sys_id. Base on the code in your BR it looks like you are trying to automatically approve the ritm via the approval record. I'm not sure why you would even create an approval record if you are just going to use a script to set it to approved. Can you provide better details on what you are trying to achieve?