The CreatorCon Call for Content is officially open! Get started here.

How to execute script include dynamically

Alon Grod
Tera Expert

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):

 

Screenshot 2023-10-01 at 13.41.45.png

 

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'
});


 

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage

@Alon Grod Update your script include function script like below. This should work for you

 

isTest: function() {

        var gr = new GlideRecord('u_merkaz_tom_reports');
        gr.query();
        while(gr.next()) {
           
            var part = gr.u_calculation.toString();
            part = part.split('.');

            var scriptIncludeName = part[0].replace("()", "");
            var funcName = part[1].replace("()", "");

            var scriptIncludeGR = new global[scriptIncludeName]();
            scriptIncludeGR[funcName]();
        }
},
 
 
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

5 REPLIES 5

jaheerhattiwale
Mega Sage

@Alon Grod Update your script include function script like below. This should work for you

 

isTest: function() {

        var gr = new GlideRecord('u_merkaz_tom_reports');
        gr.query();
        while(gr.next()) {
           
            var part = gr.u_calculation.toString();
            part = part.split('.');

            var scriptIncludeName = part[0].replace("()", "");
            var funcName = part[1].replace("()", "");

            var scriptIncludeGR = new global[scriptIncludeName]();
            scriptIncludeGR[funcName]();
        }
},
 
 
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023