GlideAjax query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 09:42 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 10:06 PM - edited 07-09-2024 10:15 PM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 01:51 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 10:23 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 01:47 AM
@Rupanjani It is on multiple records. It should give the record number on which either date/number is missing