Glide Record not found for hasNext

Tim T
Tera Contributor

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?

 

function onSubmit() {
 
    // Retrieve the values of the 'location' variables
    var location = g_form.getValue('location'); // Replace 'location' with the actual variable name
 
    // Query the incident table for matching records
    var incidentGr = new GlideRecord('incident');
        incidentGr.addQuery('u_property_location',location); // Replace with the actual field name
        incidentGr.addQuery('state','IN','1,2,3'); // Submitted (1) or Acknowledged (2) or Work in Progress (3)
        incidentGr.query();
 
    // Check if any matching incidents exist
if (incidentGr.hasNext()) {
    
// Create a confirmation message
var confirmMessage = confirm("There is already a ticket open for reporting an issue with. Do you want to proceed with opening this ticket?");
 
// Display the confirmation pop-up
if (confirmMessage == false) {
// If the user cancels, prevent the form from submitting
                return false;
            }
}
        }

 

10 REPLIES 10

JenniferRah
Mega Sage

There's a limit to the commands you can use on a Portal catalog client script. So for your statement

incidentGr.query();

You would need to add a function below that to handle the processing of the query, so it would look like this: 

 

incidentGr.query(processQuery);
 
function processQuery(incidentGr){
    if (incidentGr.hasNext()) {
     ... 
    }
}

Unfortunately, you can't return false from within that function to the entire client script, so doing this in an onSubmit script doesn't work well. You will need to either do it in an onBefore Business Rule or use an AJAX call to a script include as others have suggested.