GlideAjax question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 09:48 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-12-2024 12:06 AM
My client side has list collector field from where i am fetching multiple sys ids of records. I want to pass these sysids to server side glideajax and display message on which records the number and date is empty return those as alert msgs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 12:35 AM
But this is always returning true while trying to alert the answer for the records which has empty date and number also
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 12:45 AM
Can you try this below code,
var sysIds = this.getParameter('sysparm_query').split(','); // Split the sys_ids into an array
var grrec = new GlideRecord('xyz');
grrec.addQuery('sys_id', 'IN', sysIds); // multiple sys ids
grrec.query();
while (grrec.next()) {
if (grrec.number.nil() || grrec.xdate.nil()) {
return 'false: ' + grrec.number;
}
}
return 'true';
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 01:08 AM
Yes, checking for negation could be the reason. We can either check for nil or add additional query to avoid fetching the unmatched records as well.
Other issue I am seeing with this is it will not return all the sys_ids. Instead, can store all the required sys_ids at once and return it after the loop processing is complete like this-
function test(){
var sysIds = 'c0cf7954874023003c1c8467a7cb0b54, 1c832706732023002728660c4cf6a7b9';
var grrec = new GlideRecord('incident');
grrec.addQuery('sys_id', 'IN', sysIds); // multiple sys ids
grrec.addNullQuery('action_status');
grrec.addNullQuery('activity_due');
grrec.query();
if(!grrec.hasNext())
return true;
var abc = [];
while (grrec.next()) {
if (!grrec.action_status|| !grrec.activity_due) {
abc.push('false'+ grrec.number);
}
}
return abc;
}
gs.log(test());