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

Help With On Submit Script Check for existing Active Records

Nic Omaha
Tera Guru

I have a record producer that is creating a record on a custom table inherited from task. On submit I would like to check if an existing ACTIVE record exists with the same order number. Currently I have the script working if ANY record exists but cant seem to figure out how to add in the Active query. Any help would be appreciated. Also a bonus would be if we could also prompt the record numbers found. 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var orderId = g_form.getValue('u_order_number');
    var gr = new GlideRecord('u_flooring_measures');
    gr.addQuery('u_order_number', orderId);
    gr.query();

    if (gr.next()) {
        alert("Sorry someone is already working on this!");
        return false;
    }
}

  

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi @Nic Omaha ,

Add the condition for active status.

 

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var orderId = g_form.getValue('u_order_number');
    var gr = new GlideRecord('u_flooring_measures');
     gr.addQuery('active', true) ;   // or gr.addActiveQuery();  custome table extends Task table then active should be there  
    gr.addQuery('u_order_number', orderId);
    gr.query();

    if (gr.next()) {
        alert("Sorry someone is already working on this!");
        return false;
    }
}

 

 

AshishKMishra_0-1700259622254.png

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

4 REPLIES 4

Brian Lancaster
Tera Sage

You can use one of the following.

gr.addActiveQuery()

or

gr.addQuery('u_active', true); note that I'm just guessing the active field would have a u_ at the beginning.

AshishKM
Kilo Patron
Kilo Patron

Hi @Nic Omaha ,

Add the condition for active status.

 

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var orderId = g_form.getValue('u_order_number');
    var gr = new GlideRecord('u_flooring_measures');
     gr.addQuery('active', true) ;   // or gr.addActiveQuery();  custome table extends Task table then active should be there  
    gr.addQuery('u_order_number', orderId);
    gr.query();

    if (gr.next()) {
        alert("Sorry someone is already working on this!");
        return false;
    }
}

 

 

AshishKMishra_0-1700259622254.png

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Thank you so much! This worked perfectly I was really close! Any idea on how we might add what the record number found that matches in the alert? In a perfect world we would like to alert there's already something open and easily get them to that record. Not sure quite how to attack that but your script definitely solves most of my problems. Thanks again! 

If you review the script code the "orderId" which you are passing in "gr.addQuery()" is the match. So if want to add that order number in the alert message replace the aler() as below.

 

alert("Sorry someone is already working on this! "+gr.u_order_number);

 

let me know if this works for you or not.


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution