logo

NJP

Getting response from a script field using GlideScopedEvaluator

Import · Mar 05, 2019 · article

GlideScopedEvaluator API allows you to get the response from a "Script" field. Here is an example in detail.

1. Create a Table like this

image

2. Create a record like this

image

3. Now, open Background script and get the response from Script field like this (set "myrequest" to 1)

var gr = new GlideRecord('u_glide_scope_evaluator_example');

gr.addQuery('sys_id','97d71738db003300a22c2fb7489619ca');

gr.query();

if(gr.next()){

var evaluator = new GlideScopedEvaluator();

evaluator.putVariable('myrequest',1);

var result = evaluator.evaluateScript(gr,'u_script',null);

gs.print(result.mystring);

}

4. Run the background script and you will see the following result.

image

5. Now, change the "myrequest" value to 2, you will see like this

image

This will be very much useful when you have a repeated code to be execute and to Customize based on a response.

View original source

https://www.servicenow.com/community/developer-articles/getting-response-from-a-script-field-using-glidescopedevaluator/ta-p/2327598