Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to pass the parameter value of script include from workflow

DB1
Tera Contributor

Hi All,

 

I have the below script include and I use it from a catalog client script where I was able to pass a variable field value as parameter from client side.

I was thinking to re-use the same Script Include for another purpose which I need to use from Workflow because the return value is all I need to use.

However I am not sure how to pass the parameter value from Workflow.

Need help on the same.

TIA

var getAppname = this.getParameter('sysparm_app_name');//need help here
		var getsysid = this.getParameter('sysparm_sysid');
		var grgetCI = new GlideRecord('cmdb_ci_service');
		grgetCI.addEncodedQuery('u_application_name!=NULL');
		grgetCI.addQuery('u_application_name',getAppname);			
		grgetCI.query();
		var CIlist = "";
		while(grgetCI.next()){				
			if(CIlist == ''){
				CIlist = grgetCI.used_for.toString();
			}

 

@Danish Bhairag2 @Tai Vu @Ankur Bawiskar 

7 REPLIES 7

Aman Kumar S
Kilo Patron

Hi @DB1 

So there is a concept of using client callable script include and server side script includes, first is meant to be called by client script and other by a server script and as we know worklfow uses server side, I'm afraid you will have to recreate the function in a new script include and call from workflow.

As there are security aspects to it, I would suggest the above approach.

Best Regards
Aman Kumar

DB1
Tera Contributor

Hi, I am still stuck with it. If I have to create a new Script Include. What should I include or not from my script above. Could you please suggest?

Amit Gujarathi
Giga Sage
Giga Sage

Hi @DB1 ,
I trust you are doing great.
Here's an example of how you might refactor your Script Include:

var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
    initialize: function() {
    },

    getCIList: function(appName, sysId) {
        var grgetCI = new GlideRecord('cmdb_ci_service');
        grgetCI.addEncodedQuery('u_application_name!=NULL');
        grgetCI.addQuery('u_application_name', appName);         
        grgetCI.query();
        var CIlist = "";
        while(grgetCI.next()){                
            if(CIlist == ''){
                CIlist = grgetCI.used_for.toString();
            }
        }
        return CIlist;
    },

    type: 'MyScriptInclude'
};

Workflow's script activity:

var si = new MyScriptInclude();
var appName = /* retrieve your app name here */;
var sysId = /* retrieve your sysId here */;
var ciList = si.getCIList(appName, sysId);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi