The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

To Get all variables from catalog item

debo1
Kilo Contributor

How to get all the catalog item by using Business Rule or by using client script from Record Producer.

1 ACCEPTED SOLUTION

The SN Nerd
Mega Sage
Mega Sage

What is the Business Requirement?

 

You can get them via a report:

 

https://docs.servicenow.com/bundle/istanbul-performance-analytics-and-reporting/page/use/reporting/task/create-list-report-with-variable-columns-rows_RB.html

 

Or a script like below will output all variable values:

 

var grRequestedItem = new GlideRecord('sc_req_item');
grRequestedItem.setLimit(10);
grRequestedItem.query();
while (grRequestedItem.next()) {
 gs.addInfoMessage('Variables for ' + grRequestedItem.getDisplayValue());
  for (var prop in grRequestedItem.variables) {
    if (grRequestedItem.variables.hasOwnProperty(prop) ){
     var variable =  grRequestedItem.variables[prop];
      gs.addInfoMessage(prop + ':' + variable);
    }
  }
}

 Output

Variables for RITM0010006
acrobat:false
photoshop:false
Additional_software_requirements:
Variables for RITM0010007
new_email:jo.asd@asdas.com
Variables for RITM0010008
ergonomic_office:
Variables for RITM0010009
acrobat:true
photoshop:true
Additional_software_requirements:1

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

6 REPLIES 6

The SN Nerd
Mega Sage
Mega Sage

What is the Business Requirement?

 

You can get them via a report:

 

https://docs.servicenow.com/bundle/istanbul-performance-analytics-and-reporting/page/use/reporting/task/create-list-report-with-variable-columns-rows_RB.html

 

Or a script like below will output all variable values:

 

var grRequestedItem = new GlideRecord('sc_req_item');
grRequestedItem.setLimit(10);
grRequestedItem.query();
while (grRequestedItem.next()) {
 gs.addInfoMessage('Variables for ' + grRequestedItem.getDisplayValue());
  for (var prop in grRequestedItem.variables) {
    if (grRequestedItem.variables.hasOwnProperty(prop) ){
     var variable =  grRequestedItem.variables[prop];
      gs.addInfoMessage(prop + ':' + variable);
    }
  }
}

 Output

Variables for RITM0010006
acrobat:false
photoshop:false
Additional_software_requirements:
Variables for RITM0010007
new_email:jo.asd@asdas.com
Variables for RITM0010008
ergonomic_office:
Variables for RITM0010009
acrobat:true
photoshop:true
Additional_software_requirements:1

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hi @Paul Morris ,

How do you modify your script to only show the variables from a specific RITM?

Thanks!
Harriet

 

Hi Harriet,

You can change the query of the script and add your specific RITM sys_id.

var cat_item = '99e872e6db1dbe447fc2f7adae9619d8';
var catVarValues = '';
var grRequestedItem = new GlideRecord('sc_req_item');
// grRequestedItem.setLimit(10);
// grRequestedItem.addEncodedQuery('numberSTARTSWITHRITM0028764');
grRequestedItem.query();
if (grRequestedItem.get(cat_item)) {
    // gs.addInfoMessage('Variables for ' + grRequestedItem.getDisplayValue());
    // gs.info(JSON.stringify(grRequestedItem.variables, null, 4));
    for (var prop in grRequestedItem.variables) {
        if (grRequestedItem.variables.hasOwnProperty(prop)) {
            var variable = grRequestedItem.variables[prop];
            catVarValues = catVarValues + prop + ':' + variable + '\n';
        }
    }
}
gs.info('Summary: \n' + catVarValues);

Hope this works.

Regards,

Swarnadeep Nandy

Thank you, @Swarnadeep Nandy !