The simple Script Include / Client Script - check if the table has records

MysUser
Tera Contributor

Hello,

I have a client script that trigger the script include - this should give the answer "true" whet the table "u_proc" has at least one record. Something is wrong and I get the response "null" (the response should be "true", because the table has records). Do you know what is wrong?

Client Script:

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

var ga = new GlideAjax('test'); //This argument should be the exact name of the script include. 
ga.addParam('sysparm_name', 'testfunction'); //sysparm_name is the name of the function in the script include to call.
ga.addParam('sysparm_my_name', 'aaa'); //This is an optional parameter which we can reference in the script include. 
//ga.getXML(myCallBack); //This is our callback function, which will process the response.
	

function myCallBack(response) { //the argument 'response' is automatically provided when the callback funciton is called by the system.
    //Dig out the 'answer' attribute, which is what our function returns. 
	
    var greeting = response.responseXML.documentElement.getAttribute('answer'); 
	
    alert(greeting); //alert the result to make sure all is well.

}
}

Script Include:

var test = Class.create();
test.prototype = {
    initialize: function() {
		
		
    },
	
	testfunction: function(){
		var userName = this.getParameter('sysparm_my_name');
		var target = new GlideRecord('u_proc'); 
		//target.addQuery('u_user', userName);
		target.query(); // Issue the query to the database to get relevant records 
		while (target.next()) { 
		
			return 'true';
	}
		
	},

    type: 'test'
};
6 REPLIES 6

Shashwat  Saxen
Giga Expert

var test = Class.create();
test.prototype = {
initialize: function() {

},

testfunction: function(){
var userName = this.getParameter('sysparm_my_name');


var target = new GlideRecord('u_proc');


target.query();                       // Issue the query to the database to get relevant records

if(target.next()) {                  //use if instead of while

return true;
}
return false;                                //return false if there is no record found
},

type: 'test'
};

Inactive_Us1957
Kilo Guru

Hi,

 Please uncomment the "ga.getXML(myCallBack);" code in the client script.

Thanks