Using Script Include on the Workflow

babarat1
Tera Contributor

Hi All,

We have the below script include as follows

 

var CheckDevProdCIenv_WF = Class.create();
CheckDevProdCIenv_WF.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getCI: function(getAppname) {

		////var getAppname = this.getParameter('sysparm_app_name');
		//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();
			}
			else
			{
				CIlist = CIlist + ", "+ grgetCI.used_for.toString();
			}
		}
		var answer = CIlist;	
		//JSON.stringify(answer);
		return JSON.stringify(answer);
		//return answer;

	},

	type: 'CheckDevProdCIenv_WF'
});

 

Once the u_application_name is passed it would return the answer as I mean the CIlist should return Dev/Prod/ Test

 

I am trying to use the above SI in a workflow as below

gs.log("WF AppName " +current.variables.product.u_application_name);// this log returns right value

var CIlist = new CheckDevProdCIenv_WF().getCI(current.variables.product.u_application_name.toString());
gs.log("WF User CI ENv " +CIlist);// this does not work

 

it shows undefined only

I tried without .toString() also.

Please help us with the same.

 

TIA

@Dr Atul G- LNG @Danish Bhairag2 @Tai Vu @Anil Lande 

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

If current.product.u_application_name logs the expected value, why are you using current.variables.product.u_application_name in the function call?  Is the Script Include in the Global Scope? If you add a log at the beginning of the Script Include can you confirm that it is running?

Hi,

Thanks for the reply. It was not just current.product, it was current.variables.product.u_application_name); and the log returns right value. I have updated my Post as well.

It is a Global SI

And I tried to have the log in first place

getCI: function(getAppname) {
 
////var getAppname = this.getParameter('sysparm_app_name');
//var getsysid = this.getParameter('sysparm_sysid');
gs.log("Inside Script Include");
 
I see the log, Yes

That's a good start.  Add some more logging to see what's going on:

	getCI: function(getAppname) {
        gs.log('SI Appname = ' + getAppname);
		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()){		
        gs.log('SI inside while');		
			if(CIlist == ''){
				CIlist = grgetCI.used_for.toString();
			}
			else
			{
				CIlist = CIlist + ", "+ grgetCI.used_for.toString();
			}
		}
		var answer = CIlist;	
        gs.log('SI answer = ' + answer);
		//JSON.stringify(answer);
		//return JSON.stringify(answer);
		return answer;
	},

Hi Brad,

 

Yes all of the logs returns right values

SI inside while*** Script
2023-12-12 09:12:54 Information SI inside while *** Script
2023-12-12 09:12:54 Information SI answer = Development, Production *** Script
2023-12-12 09:12:54 Information SI Appname = ABC- DHL App *** Script
2023-12-12 09:12:54 Information SI Inside Script Include