- 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-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
Amit Verma
- 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_GlideEvaluat...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 10:05 PM
Hi @vermaamit16 . @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
Amit Verma