
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 03:38 AM
Hi All,
I have a requirement for the script execution in the flow action. We have created a Custom table with a field type as "Script". Now, If any script is written in that field. I need to run that script in the flow action. How can I achieve this? I tried by giving the "input.variable" in the Script flow. But no luck and I tried to call directly the field inside the flow script but also it didn't worked. But when I have written the script in the custom flow action script and defined only 1 input. It worked. Can anyone help me on this? PFA images for ref.
Thanks,
Ripunjai
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 04:07 AM
Hi @Community Alums
Let me give you a step by step explanation. Suppose I have a custom table 'u_testing' with a Script type column 'u_inputscript' which has a simple script to return sum of two numbers. Refer below screenshots :
Now if the following script from Scripts-Background, I will get the sum of both the numbers i.e. 6
We are already passing the GlideRecord reference while calling the evaluateScript method. It expects the GlideRecord reference and the name of the column in which your script resides. Hope it clears your query.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 04:20 AM
Hi @Community Alums
You can make use of GlideScopedEvaluator() API. Refer below post and give this a try in your Script Step :
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 04:52 AM
@Community Alums You can use GlideScopeEvaluator to evaluate the script stored in a field on a table.
Here is an example.
// Setting up a record that contains the script to be executed.
var now_GR = new GlideRecord('u_global_table');
now_GR.u_short_description = 'Calculate Addition';
now_GR.u_test_script = "result = x + y";
now_GR.insert();
var evaluator = new GlideScopedEvaluator();
evaluator.putVariable('x', 100);
evaluator.putVariable('y', 200);
evaluator.evaluateScript(now_GR, 'u_test_script', null);
gs.info(evaluator.getVariable('result'));
Please refer the URL to know more about GlideScopeEvaluator https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/no-namespace/c_GlideEvaluatorScopedAPI#r_ScopedGlideEvaluatorGlideScopedEvaluator?navFilter=glideScope

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 10:05 PM
Hi @Amit Verma . @Sandeep Rajput ,
Thanks for helping. I updated the script the same way as per the doc. But it shows an error stating the variable is not defined. Can you check, did I updated the Flow designer action and script the correct way?
Script added in the custom table
Thanks,
Ripunjai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 10:57 PM - edited ‎02-27-2024 10:59 PM
Hi @Community Alums
Update the flow action script as below and retry :
var grFlowActionFlowAction= new GlideRecord('u_service_id');
grFlowActionFlowAction.addQuery('sys_id','0080be48dba48120fbc899fbd3961964');
grFlowActionFlowAction.query();
if(grFlowActionFlowAction.next()){
var evaluator = new GlideScopedEvaluator();
gs.info(evaluator.evaluateScript(grFlowActionFlowAction, 'u_script', null))); // Please replace u_script with your script field name in the table
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.