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.

Return sys id in array script include

DB1
Tera Contributor

Hello All,

 

I have the following Script Include where I need to return multiple sys ids in array.

Could you please help with how to achieve the same?

SI:

 

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 myStr = "";
		var SYSIDlist = [];
		while(grgetCI.next()){	

			if(CIlist == ''){
				CIlist = grgetCI.used_for.toString();
				//myStr = grgetCI.name;
				SYSIDlist.push(grgetCI.sys_id.toString());
			}
			else
			{
				CIlist = CIlist + ", "+ grgetCI.used_for.toString();
				//myStr = myStr + ", " + grgetCI.name;
				SYSIDlist = SYSIDlist + ", " + grgetCI.sys_id.toString();
			}
		}
		var answer = CIlist + "\n" + SYSIDlist;		
		gs.log('SI answer = ' +  + "Sys ID 1 " +SYSIDlist[0] + "Sys ID 2 " +SYSIDlist[1]);
		//JSON.stringify(answer);
		return JSON.stringify(answer);	
		//return answer;

	},

TIA

@Dr Atul G- LNG @Ankur Bawiskar @Maik Skoddow @Anil Lande 

10 REPLIES 10

DB1
Tera Contributor

It worked @Saurabh Gupta  and @Bert_c1 

Thanks