onSubmit client script starts on update of a record too

gabrielon
Kilo Contributor

Hi,

I have a weird behaviour with a client script that should take place only on a submit of a new record, but it works on update too.

The script is very simple:

function onSubmit()

{

      var gr = new GlideRecord('table');

gr.addQuery('key',g_form.getValue('key'));

gr.query();

if(gr.next()){

                                        g_form.addErrorMessage('The record already exists');

                                        g_form.setValue('key',''); //it delete the value

                                        return false;

                                      }

}

The script should check if a name is already present in a list when submitting a new record, and prevent it to submit, deleting the value.

It actually works, but it starts also when I update or save the record (with Update or Save Button), deleting the key field.

Weird, isn't it?

1 ACCEPTED SOLUTION

ark6
Mega Guru

Okay..you could put g_form.isNewRecord() to check if the record is new



If no, then return false.


View solution in original post

5 REPLIES 5

ark6
Mega Guru

Okay..you could put g_form.isNewRecord() to check if the record is new



If no, then return false.


gabrielon
Kilo Contributor

Thank you arka for the quick answer! Now it's okay.


I still wonder why they call it "onSubmit" and it works on Update too. 😕


Hi Gabriele,



onSubmit client scirpt trigger whenever an update / insert opration is tried with DB.


This is expected behavior, same client script gives you more control with g_form.isNewRecord() when record is not yet inserted.


Not sure..I think its a terminology that SNOW uses when any client side function tries to interact with the server...