for(vars in current.variable_pool) what this script is doing

Santhosh23
Tera Expert

for(vars in current.variable_pool) 

Can any one please explain what the above line is doing

3 REPLIES 3

Dhananjay Pawar
Kilo Sage

Hi,

 To get the values from a variable set we generally use variable_pool instead of the variable.

Thanks,

Dhananjay.

Joshwa Antony S
Mega Guru

Hello Santhosh,

The code is to iterate through the variables that are stored in variable editor section. By this way you can read the variables (answers for questions that you answered during catalog item submission).

The code will give you both Question and Answer as key value pair.

Eg:-

var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", "9d992060db51401071897b823996193f"); //Your RITM sysid here
gr.query();

if (gr.next()) {

    for (var s in gr.variable_pool) {
        var val = gr.variable_pool[s];
        gs.print("Key: " + s);
        gs.print("Value: " + val);
    }
}

Output in Background script:

*** Script: Key: type
*** Script: Value: internal
*** Script: Key: internal_destination
*** Script: Value:
*** Script: Key: line_one
*** Script: Value: The Nilgiris
*** Script: Key: line_two
*** Script: Value:
*** Script: Key: city
*** Script: Value: Ooty

 

find_real_file.png

 

Regards,

JAS

Sumanth16
Kilo Patron

Hi ,

 

I am not sure but variable_pool get all the variables related to that catalog item (or) request item.

So for loo means it is iterating each variable in associated records.

 

Please refer below link:

https://community.servicenow.com/community?id=community_question&sys_id=ac7cc7a5db9cdbc01dcaf3231f96...

 

 

Please mark it as helpful (or) correct if it is helpful

 

Thanks,

Sumanth