logo

NJP

Use of GlideScopedEvaluator APIs- evaluateScript() function

Import · Apr 25, 2022 · article

The GlideScopedEvaluator API allows you to evaluate scripts in a GlideRecord field from both scoped and global server scripts.

The GlideScopedEvaluator API evaluates scripts within the script field type. The scope of the record defines the scope of the script.

The most common method used from these APIs-

evaluateScript(GlideRecord grObj, String scriptField, Object variables)-

var test_GR = new GlideRecord('x_custom_table');test_GR .short_description = 'Testing GlideScopedEvaluator APIs Method';test_GR.u_test_script = gs.getUser().getName() + " says " + "Hi/Hello";test_GR.insert();//setup variables to be used by the scriptvar vars = {'Hi/Hello' : 'hello'}; //Evaluate the script from the fieldvar evaluator = new GlideScopedEvaluator();//gs.info(evaluator.evaluateScript(test_GR , 'test_script', vars));// Now retrieve the resultevaluator.evaluateScript(test_GR , 'u_test_script', vars);

gs.info(evaluator.getVariable('result'));

image

View original source

https://www.servicenow.com/community/now-platform-articles/use-of-glidescopedevaluator-apis-evaluatescript-function/ta-p/2306121