GlideAjax query

tanz
Tera Expert

I want to write a client script which will perform some actions (display alert that number or date is empty ) in catalog item when the number and date fields from table xyz .

 

For this GlideAjax script should be written which should check on the records and return some flag if one of fields in empty.

 

i want to know how to achieve this.

var gr = new GlideRecord('xyz');
gr.addQuery('sys_id','IN' ,sysIds); // pass the sysids in the glideajax query param
gr.query();
{ if any one of the number or date is empty 
return which field is empty against which number
}
In client script 
alert those and do some action using glideajax
6 REPLIES 6

Vrushali  Kolte
Mega Sage

@tanz 

 

You can write the GlideAjax script as follow in the client script & server script -

 

//Client- side code
var ga = new GlideAjax('SI_name');
ga.addParam('sysparm_name','method_name');
ga.addParam('sysparm_param1'," param1"); // Set parameter
ga.getXML(getEmptyFields);

// the callback function for returning the result from the server-side code
function getEmptyFields(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer != ''){
alert('Fields are empty '+ answer.flag +' '+ answer.field);
}
}


//Server- side code
method_name : function(){
var sys_id = this.getParameter('sysparm_param1');
var flag = 'false';
var obj = {};
var gr = new GlideRecord(table_name);
gr.addQuery('sys_id',sys_id);
gr.query();
if(gr.number == ''){
flag = 'true';
obj.flag = flag;
obj.field= 'number';
}
if(gr.date == ''){
flag = 'true';
obj.flag = flag;
obj.field = 'date';
}
if(flag == 'true')
return JSON.stringify(obj);
else
return '';
}

 

 

Please mark the answer helpful or accept it, if it works for you!!

@Vrushali Kolte , what will be solution for multiple records. It should give the number for which ones the fields are empty values. either date/number is empty. or both are empty . like this it should display alerts.

Rupanjani
Giga Guru

Hi @tanz,

 

Are you checking the date/number being empty on a single record/multiple records?

As I see you mentioned sysIDs. 

Can you elaborate the issue, so it would be easier to assist you.


Mark the response correct and helpful if the answer assisted your question.

@Rupanjani It is on multiple records. It should give the record number on which either date/number is missing