g_form.submitが動かない。

陳立東
Giga Expert

クライアントスクリプトのonSubmitにて、
クラシック環境のフォームの「g_form.submit()」は動かない。

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@陳立東 

this onSubmit is for catalog item?

Please share some more details, what are you trying to validate in onSubmit

Why not have the validation on change of your field/variable?

also check these links

How To: Async GlideAjax in an onSubmit script 

How to validate before onSubmit in Mobile/Service Portal 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Rajesh Chopade1
Mega Sage

Hi @陳立東 

calling "g_form.submit()" within the onSubmit script would essentially trigger the submission again, leading to an infinite loop or unexpected behavior. If you need to programmatically submit the form based on certain conditions, you should avoid calling g_form.submit()  directly inside the onSubmit client script. Instead, you can rely on the default form submission behavior. Use return false to prevent submission if needed, or rely on form validation to control submission behavior.

 

function onSubmit() {
    if (g_form.getValue('field_name') == 'some condition') {
        alert('Condition met! Submission will be prevented.');
        return false; // Prevent submission
    }

    return true; // Allow submission
}

 

I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

Rajesh

 

I think so,but g_form.submit() is not wroking.

why calling "g_form.submit()" within the onSubmit script dos not trigger the submission now?

Ankur Bawiskar
Tera Patron
Tera Patron

@陳立東 

can you share your script here rather than image?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@陳立東 

this onSubmit is for catalog item?

Please share some more details, what are you trying to validate in onSubmit

Why not have the validation on change of your field/variable?

also check these links

How To: Async GlideAjax in an onSubmit script 

How to validate before onSubmit in Mobile/Service Portal 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader