- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 07:42 AM
Hi
I'm writing a new application and i want to add a cutom script field to a table that a workflow will locate via a glideRecord.
The idea is the workflow will execute the script.
I'm just a little lost on how to tell ServiceNow to execute a script in a script field on a custom table.
I expected a command like "gr.u_script.run" but cant find any reference.
Any suggestions welcome
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 07:49 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 05:35 AM
Hi Simon,
The answer to this one is to use the getVariable() method on the GlideScopedEvaluator object. See the example in the docs where they multiple x * y and return result. The calling script gets access to the result using getVariable().
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=GlideEvaluator-GlideScopedEvaluator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 06:10 AM
I have tried that, but it still doesn't work for me. Here is what I have. Perhaps you can spot the gap.
The part of my script include that calls the evaluator:
if (signature) {
var sigFile = new GlideRecord('u_client_signature');
sigFile.get(signature);
if (!sigFile.isValidRecord()||JSUtil.nil(sigFile.getValue('u_script')))
return "Error";
gs.info("DEBUG: Scipt Record Found! - " + sigFile.getValue('u_script'));
var evaluator = new GlideScopedEvaluator(sigFile);
evaluator.evaluateScript(sigFile, 'u_script', null);
signature = evaluator.getVariable('result');
}
return signature;
rn signature;
Here is the script that it calls in the "sigFile" GlideRecord:
var answer = testScript();
function testScript() {
return "test";
}
Here is the output from background script when entering gs.info(new clientSignature().run());
*** Script: DEBUG: Scipt Record Found! -
var answer = testScript();
function testScript() {
return "test";
}
*** Script: null

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 06:13 AM
It's not a 'return' thing, it's looking for a variable called 'result'.
Try this in your script field...
(function () {
var result = 'Test';
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 06:18 AM
still null
*** Script: DEBUG: Scipt Record Found! - (function () { var result = 'Test'; })();
*** Script: null
I had previously tried similar changes. set the var answer and tried to retrieve "answer" from the evaluator.
I'm stumped.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 06:23 AM
Hi Simon,
I know it's possible. I wrote a lab for CreatorCon a couple year ago that demonstrates this... If you PM me, I can send you a link to the PDF.