Glide Record not found for hasNext
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 05:44 AM
My requirements are to query the Incident table on submit from the portal to identify any potential similar issues at the same location; alert the user they may be creating a duplicate record; and confirm they want to proceed with opening the new Incident. Using the below script in a Catalog Client Script, however, I do not get the expected confirmation window. I even commented out the query for the custom location field and tried to pull results for any Incidents in an open status. Still, I get no confirmation window. Is there something I'm missing from the below code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 09:44 PM
@Tim T Can you apply some log and check where it is getting failed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 08:28 AM
I added logs below. The location in the log is correct. The response comes back with a null value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2025 06:47 AM
Hello @Tim T
Your script has a few issues that might be preventing the confirmation window from appearing. Here are the key problems and solutions:
Issues in Your Code:
- onSubmit() Needs to Return false to Prevent Submission
- If you want to stop form submission, onSubmit must return false. Right now, your function only prevents submission if a duplicate is found but doesn’t return true otherwise.
- GlideRecord (GlideAjax is Required Instead)
- GlideRecord does not work on the client-side. It only runs on the server.
- You must use GlideAjax to query the incident table from a client-side script.
onSubmit Client script:
function onSubmit() {
var location = g_form.getValue('location'); // Replace with actual field name
if (!location) {
return true; // Proceed if no location is selected
}
var ga = new GlideAjax('CheckDuplicateIncident');
ga.addParam('sysparm_name', 'checkForDuplicates');
ga.addParam('sysparm_location', location);
var result = ga.getXMLWait(); // Synchronous call
var duplicateExists = result.documentElement.getAttribute("answer") == "true";
if (duplicateExists) {
var confirmMessage = confirm("There is already an open ticket for this location. Do you want to proceed?");
if (!confirmMessage) {
return false; // Prevent submission
}
}
return true; // Proceed with submission
}
Script include:
var CheckDuplicateIncident = Class.create();
CheckDuplicateIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkForDuplicates: function() {
var location = this.getParameter('sysparm_location');
var gr = new GlideRecord('incident');
gr.addQuery('u_property_location', location);
gr.addQuery('state', 'IN', '1,2,3'); // Open states
gr.query();
return gr.hasNext(); // Returns true if a duplicate exists, false otherwise
}
});
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 10:23 AM
Juhi,
Thank you for your response and suggestion. When I tried executing the scripts you provided, I received the below console error messages.
GlideAjax.getXMLWait is no longer supported
(g_env) [SCRIPT:EXEC] Error while running Client Script "No Duplicate Confirmation - Cameras": TypeError: Cannot read properties of undefined (reading 'documentElement')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 09:56 PM
@Tim T Yes getXMLWait() do not work on portal side instead try to update your client script something like below
function onSubmit() {
if (g_scratchpad.isFormValid) {
return true;
}
var location = g_form.getValue('location'); // Replace with actual field name
if (!location) {
return true; // Proceed if no location is selected
}
var ga = new GlideAjax('CheckDuplicateIncident');
ga.addParam('sysparm_name', 'checkForDuplicates');
ga.addParam('sysparm_location', location);
return false;
var result = ga.getXMLWait(); // Synchronous call
var duplicateExists = result.documentElement.getAttribute("answer") == "true";
if (duplicateExists) {
var confirmMessage = confirm("There is already an open ticket for this location. Do you want to proceed?");
if (!confirmMessage) {
return false; // Prevent submission
}
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Please mark correct/helpful if this helps you