- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 03:41 AM
Hi,
have the table u_merkaz_tom with the string field 'u_calculation'. This field holds inside a name of a script include and a function name, for example:
Median().isMedian()
How can I glide record this table and execute the script includes one by one according to the value inside 'u_calculation'.
I tried this way but its not working (im not getting the log):
 
var reportsMerkazTom = Class.create();
reportsMerkazTom.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isTest: function() {
var gr = new GlideRecord('u_merkaz_tom_reports');
gr.query();
while(gr.next()) {
var part = gr.u_calculation.toString();
var scriptIncludeName = part.split('.')[0];
var funcName = part.split('.')[1];
var scriptIncludeGR = new GlideScriptInclude(scriptIncludeName);
scriptIncludeGR[funcName]();
}
},
type: 'reportsMerkazTom'
});
var Median = Class.create();
Median.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isMedian: function() {
gs.log('Mays');
},
type: 'Median'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 05:35 AM
@Alon Grod Update your script include function script like below. This should work for you
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 03:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 04:24 AM
@Alon Grod Apart from the answer shared one of the previous thread (related to Calculated field), you can also choose to make u_calculation a script type field.
You can put your script inside this field. Now question comes that how can we evaluate this script, to evaluate a script available on a field ServiceNow has provided GlideScopedEvaluator API.
Here is a sample how you can use this API.
var now_GR = new GlideRecord('global');
now_GR.u_short_description = 'Calculate Addition';
now_GR.u_test_script = "result = x + y";
evaluator.evaluateScript(now_GR, "script")
now_GR.insert();
var evaluator = new GlideScopedEvaluator();
evaluator.putVariable('x', 100);
evaluator.putVariable('y', 200);
evaluator.putVariable('result', null);
evaluator.evaluateScript(now_GR, "script")
now_GR.insert();
For more information on GlideEvaluator please refer to the documentation https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/GlideEvaluatorAPI
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 04:27 AM
@Sandeep Rajput hi, but if i want to do it in my way, using the scrips that I shared, how can I call the script include and the function dynamically? what do i need to change?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 04:52 AM
@Alon Grod Calculated field approach which I suggested in the previous thread is one of the best ways to calculate the values at the run time.