The CreatorCon Call for Content is officially open! Get started here.

need help in the code

Community Alums
Not applicable

Before creation of the new queries in ‘custom application ' i have to check total how many records are present in the table for the same person who selected as requester in this current record has pending open issues, yet and i have to check if total no of records present in the system is 7 or greater then 7,i have  put an alert to person who is creating this request and message should be ‘Already 7 queries are present for this requester, Please delete any previous query then try to create new one for this requester’.

 

i wrote onsubmit client script

 

 var requester = g_form.getValue('u_requester');
  var gr = new GlideRecord('chromatech_customer_queries');
    gr.addQuery('u_requester', requester);
    gr.addQuery('active''IN''1,2'); // Assuming '1' and '2' are statuses for pending queries
    gr.query();

    var recordCount = 0;

    while (gr.next()) {
        // Increment the record count for each matching record
        recordCount++;
    }
    
    if (recordCount >= 7) {
        // Display an alert to the user
        alert('Already 7 queries are present for this requester. Please delete any previous query then try to create a new one.');
        // Prevent record insertion
        g_form.setAbortAction(true);
 
the above code is not working .. kindly help me 
2 REPLIES 2

jonsan09
Giga Sage
Giga Sage

You'll want to move your GlideRecord query into a script include and call the script include from your client script. GlideRecord is a server side script API.

Bert_c1
Kilo Patron

Hi Pyira,

 

You are missing a closing "}" for the 'if' code block. But otherwise your script should work. (I have done similar GlideRecord() query in Client Scripts.) It is supported, but limited. Since you are only counting records, there is no problem.  Here's an example onChange Client script for incident and the Caller field.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   // now check for active child incidents
	var incr = new GlideRecord('incident');
	incr.addQuery('parent', g_form.getUniqueValue());
	incr.addQuery('active', true);
	incr.query();
	var noRecords = incr.rows.length;
	if (incr.next()) {
		alert("There are " + noRecords + " open child incidents.");
	}
	else
		alert("There are no open child incidents.");
   
}

 

See how the number of records meeting the query is done above.