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

Deepak Ingale1
Mega Sage

You must encapsulate your code inside



if (g_form.isNewRecord()) {   if record is not submitted yet, means new record


 


}