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

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

As script include logs are correct, there is some issue with your local var name 'CIlist':

try below:

 

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

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Anil Lande
Kilo Patron

Hi @babarat1 

I tested your Script include and I was able to get the expected result. I just replaces 'u_application_name' with 'name' on my PDI (I don't have that column).

Please check you have entered the correct column name that for table(cmdb_ci_service) query in your SI.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

This is what I have:

AnilLande_0-1702390385618.png

 

 

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('name!=NULL');  // replaced column name here 
        grgetCI.addQuery('name', getAppname);    // replaced column name here 
        grgetCI.query();
        var CIlist = "";
        while (grgetCI.next()) {
            if (CIlist == '') {
                CIlist = grgetCI.used_for.toString();
            } else {
                CIlist = CIlist + ", " + grgetCI.used_for.toString();
            }
        }
        var answer = CIlist;       
        return answer;
       
    },

    type: 'CheckDevProdCIenv_WF'
});
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande