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

Get multiple answers from Script Include in workflow

babarat1
Tera Contributor

Hi All,

 

I have the following script Include:

 

	getCI: function(getAppname) {

		var grgetCI = new GlideRecord('cmdb_ci_service');
		grgetCI.addEncodedQuery('u_client_solution!=NULL');
		grgetCI.addQuery('u_client_solution',getAppname);			
		grgetCI.query();
		var CIlist = [];
		var SYSIDlist = [];
		while (grgetCI.next()) {
			CIlist.push(grgetCI.used_for + "");
			SYSIDlist.push(grgetCI.getUniqueValue());
		}
		//gs.info('SI answer = ' + +"Sys ID 1 " + SYSIDlist[0] + "Sys ID 2 " + SYSIDlist[1]);
		var answer = CIlist.join(",") + "\n" + SYSIDlist.join(",");
		gs.info("SI answer = "+answer);
		gs.info("SI answer sys id = "+SYSIDlist[0] + "- CIlist"+CIlist[0] +"CIlist -" +CIlist[1] + " " +SYSIDlist[1]);
		return answer;
		//return answer;
	},

 

 

gs.info("SI answer sys id = "+SYSIDlist[0] + "- CIlist"+CIlist[0] +"CIlist -" +CIlist[1] + " " +SYSIDlist[1]);

This info message returns answer like below:

 SI answer sys id = 0ef85272db92fb00de9f1bbf29961968- CIlistProductionCIlist -Development f1df074a0f490700552ec4dce1050e48

 

I have called the script Include in a workflow as below

var si_ci_list = new CRFCheckDevProdCIenv_WF().getCI(current.variables.product.u_client_solution);
var env = si_ci_list;
gs.log("WF Non User CI ENv " + "si_ci_list " +si_ci_list);// this log returns answer as:

WF Non User CI ENv si_ci_list Production,Development
0ef85272db92fb00de9f1bbf29961968,f1df074a0f490700552ec4dce1050e48 

However I want to differentiate the sys id meaning I want to separate the sys ids and values of Dev/ Prod and retrieve to use them for querying.

Can someone help

 

Thanks,

@Dr Atul G- LNG @Maik Skoddow @Anil Lande @Sainath N @Iraj Shaikh 

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

Hello @babarat1 ,

You can give a try to the script's below and let me know how it works for you.

Script Include:

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

    getCI: function(getAppname) {
        var grgetCI = new GlideRecord('cmdb_ci_service');
        grgetCI.addEncodedQuery('u_client_solution!=NULL');
        grgetCI.addQuery('u_client_solution', getAppname);
        grgetCI.query();

        var CIlist = [];
        var SYSIDlist = [];

        while (grgetCI.next()) {
            CIlist.push(grgetCI.used_for + "");
            SYSIDlist.push(grgetCI.getUniqueValue());
        }

        var result = {
            CIlist: CIlist,
            SYSIDlist: SYSIDlist
        };

        return JSON.stringify(result);
    },

    type: 'CRFCheckDevProdCIenv_WF'
});

 

Workflow Script:

// In your workflow script
var si_ci_list = new CRFCheckDevProdCIenv_WF().getCI(current.variables.product.u_client_solution);
var answer = JSON.parse(si_ci_list);

var SYSIDlist = answer.SYSIDlist;
var CIlist = answer.CIlist;

// Now you can use SYSIDlist and CIlist as separate arrays
gs.log("WF Non Philip User CI ENv SYSIDlist: " + SYSIDlist);
gs.log("WF Non Philip User CI ENv CIlist: " + CIlist);

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

 

 

View solution in original post

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

If you need two different arrays then you can use it like below:

getCI: function(getAppname) {

		var grgetCI = new GlideRecord('cmdb_ci_service');
		grgetCI.addEncodedQuery('u_client_solution!=NULL');
		grgetCI.addQuery('u_client_solution',getAppname);			
		grgetCI.query();
		var CIlist = [];
		var SYSIDlist = [];
		while (grgetCI.next()) {
			CIlist.push(grgetCI.used_for + "");
			SYSIDlist.push(grgetCI.getUniqueValue());
		}
		var answer = {
"CIlist" : CIlist,
"SYSIDlist" : SYSIDlist
};
		
		return JSON.stringify(answer};
		//return answer;
	},

 

In your client script you can read these arrays like below:

 

var answer = JSON.parse(response);

var SYSIDlist = answer.SYSIDlist.split(',');

varCIlist = answer.CIlist.split(',');

 

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

Hi Anil, Thanks for the reply. This is not on the client script. I want to call from workflow?

Still the logic is same and you just need.

The response will be storing retuned data of script include if you make call like below.

var response = new CRFCheckDevProdCIenv_WF().getCI(current.variables.product.u_client_solution);
var answer = JSON.parse(response);
var SYSIDlist = answer.SYSIDlist.split(',');
varCIlist = answer.CIlist.split(',');

 

you can adopt the logic as per your configurations.

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

Still, the logic was same!

I believe I had shared the logic already, it just I mentioned client script and used response variable instead of 

var si_ci_list 

 

 

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