How to get values from variable set in Business rule?

Yogesh33
Kilo Contributor

Variable set type is Multi-Row Variable Set with below three Variables:

Application: type Look up Select Box.

Application Role: type Look up Select Box.

Application Scope: type Single Line Text.

find_real_file.png

(function executeRule(current, previous /*null when async*/) {
	
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.short_description = 'Demo short description';
gr.description ='Application: '+ current.variable_pool.application+ //prints: undefined
'Application Role: '+current.variables.select_application.application_role+ //prints: [], emply array. select_application is a variable set.
'Application Scope: '+current.variables.application_scope; //prints: undefined
gr.request_item = current.sys_id;
gr.parent = current.sys_id;
gr.insert();

})(current, previous);

Here, with the help of Business rule I am creating catalog task and printing values of Variables in Description of the task.

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You can use current.variables.internal_name_of_the_mrvs to get your hands on the JSON which for the MRVS concerned. An example (= tested) on our environment:

gs.info(current.variables.u_staff_cost);

Resulted in:

[ {
"details4" : "other_general_expenses",
"date4" : "06-08-2019",
"amount_eur4" : "99,99",
"description4" : "xxx"
} ]

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You can use current.variables.internal_name_of_the_mrvs to get your hands on the JSON which for the MRVS concerned. An example (= tested) on our environment:

gs.info(current.variables.u_staff_cost);

Resulted in:

[ {
"details4" : "other_general_expenses",
"date4" : "06-08-2019",
"amount_eur4" : "99,99",
"description4" : "xxx"
} ]

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Shruti Tikhe
Tera Contributor

below is is very efficient way than Glide 'sc_multi_row_question_answer' table .

Here  is my working script.

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

var mrvs = current.variables.vendor_information;
var totalRows = mrvs.getRowCount();
var total = 0;
for (var i = 0; i < totalRows; i++) {
total = total + mrvs.getRow(i).getCell('vendor_price').getCellDisplayValue() * mrvs.getRow(i).getCell('quantity').getCellDisplayValue();
}
var req = new GlideRecord('sc_request');
req.get(current.request);
req.price = total.toFixed(2);
current.price = total;
})(current, previous);