How to access global variable sets from a scoped application script in Servicenow

Kishan Gourav
Kilo Contributor

Hi All,
I am using an aws scoped application ( aws service management connector) and from the catalog I am trying to access some global variable sets. I am able to populate the catalog with the global variable sets however when I try to populate the value from the script to send it to aws, the value or display value is not getting retrieved.

see below:
//Add custom Tags
var tags = [];
var reqFor = current.variables.req_for.getDisplayValue();// created in AWS scoped app
//var BusOwner = current.aws_business_owner.getDisplayValue(); // created on global..
//var busow = current.aws_business_owner.getDisplayValue();
var busow1 = current.variables.aws_business_owner; // global variable and doesn't fetch data from the form

if(current.variables.Tags)
tags = JSON.parse("" + current.variables.Tags);
tags.push({
Key: "Requested For",
Value: reqFor // works fine and populates the value
});

tags.push({
Key: "Division",
Value: busow1 // gives null value. **** Need suggestions here *****
});
current.variables.Tags = JSON.stringify(tags);


output:

"Key":"Environment","Value":"Development"},
{"Key":"Requested For","Value":"Ak Kostr"},
{"Key":"Division","Value":{}}] //doesnt fetch any values for global variable from the form

1 REPLY 1

Michael Jones -
Giga Sage

The scope of the variable set should not be an issue in and of itself - and you are positive that the variable in question has a value for the record being processed?

A quick check you can make is to take an item you know has the right values and run a test in a background script, both in your application scope and in the global scope and see what the results are. 

var sys_id = '<sys_id_of_a_good_record>'
var current = new GlideRecord('sc_req_item');
current.get(sys_id);

gs.info('Does it exist? ' + current.variables.aws_business_owner != undefined);
gs.info('Is there a value? ' + current.variables.aws_business_owner);
gs.info('Is there a display value? ' + current.variables.aws_business_owner.getDisplayValue());

I hope this helps!

If this was helpful, or correct, please be kind and mark the answer appropriately.

Michael Jones - Proud member of the GlideFast Consulting Team!

 

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!