Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideEvaluator

ayushcr7
Kilo Contributor

Hi All,

I have created one scripted rest api which will evaluate the script and return the result.

PFB the script.

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

var table_nm = 'incident';
var table_sys_id = '6a94f7e8db1113000327771c8c9619e8';
var target_name = 'Test';
var current = new GlideRecord(table_nm);
current.get(table_sys_id);
//Set the table map name
var grTableMap = new GlideRecord('sys_script');
grTableMap.addQuery('name', target_name );
grTableMap.query();
while(grTableMap.next()){
gs.log("Using tablemap script " + grTableMap.script);
var gc = (typeof GlideController != 'undefined') ? GlideController : Packages.com.glide.script.GlideController;
gs.log(gc);
var answer = GlideEvaluator.evaluateString(grTableMap.script);
gs.print("Table map script returning: \n\t" + answer);
gs.log("Table map script returning: \n\t" + answer);
}

return {
result:answer

};

})(request, response);

 

When i am running the script i am getting the result as Null.Glide Evaluator.evaluate string evaluates the answer to Null.

grTableMap.script has correct values.

When i am running the same script in Script->Background it gives me correct results.

Your help would be very much appreciated here.

Regards,

Ayush

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Are you running this from a scoped application scripted rest api or from global? If it's scoped you'd need to use GlideScopedEvaluator().

ayushcr7
Kilo Contributor

Its running from Global.

 

If i use eval in place of evaluateString it works fine.

Sushant Kadam1
Kilo Guru

Hi,

can somebody plz tell me what is use of GlideEvaluator(evaluateString('string')); ?

 

 

Thanx

Sushant