AjaxQuery: properties from custom table for the items selected in ListCollector

MysUser
Tera Contributor

Hi, I have a basic problem with my query. Unfortunately I don't know how to solve it.

I want to check the property WL (in the table u_systems) for the items selected in my ListCollector.

My idea was to get all items from ListCollector, create a special query and then collect all values for WL property for each row.

Problem is that this query doesn't work as it should be, it's not listing all rows as it should do.

Do you have any ideas?

 

Client Script - onChange - variable:ListCollector

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

var ListCollector = g_form.getValue('ListCollector');

var ajax = new GlideAjax("get_data");
ajax.addParam("sysparm_name","getWL");
ajax.addParam("sysparm_system_name", ListCollector);
ajax.getXML(ajaxResponse);

function ajaxResponse(serverResponse) {
		var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
		answer = JSON.parse(answer);
		alert(answer);

}}

Script Include

getWL: function(){
		
var query = '';
var data;
var zbior = this.getParameter('sysparm_system_name');
var array = [];
array = zbior.split(",");

var gc = new GlideRecord("u_systems");
for (var i=0; i< array.length; i++) {
			query += "sys_idLIKE" + array[i] + "^OR";
}
gc.addEncodedQuery(query);
gc.query();
if(gc.next()){
	gs.log("WL" + gc.u_WL);
        data += gc.u_WL;
}
return data;
},

 

1 ACCEPTED SOLUTION

AnirudhKumar
Mega Sage
Mega Sage

1. Is your client script calling the script include? I suggest add an log message right at the top to verify it first.

2. I see your query might return multiple records, so we should be using while(gc.next())

View solution in original post

2 REPLIES 2

AnirudhKumar
Mega Sage
Mega Sage

1. Is your client script calling the script include? I suggest add an log message right at the top to verify it first.

2. I see your query might return multiple records, so we should be using while(gc.next())

Thank you, it worked after using "while(gc.next())".