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

GlideModal and g_form.submit() doesn't work on new record

xiaix
Tera Guru

I have an onSubmit client script on the Incident table that invokes a GlideModal:

find_real_file.png

 

This works great.

 

Now, in the UI Page that this GlideModal is invoking has this bit of code:

find_real_file.png

 

If the Incident is NOT a new record (it has already been saved), this all works great.  However, if it IS a new record, g_form.submit() does absolutely nothing and the Incident record just sits there.

 

I know that the condition is being hit because I'm getting this in the browser's console:

find_real_file.png

 

NOTE:  Neither g_form.save() OR g_form.submit() will work when g_form.isNewRecord() evaluates to true!

 

What trickery do I need to perform to get this record to submit when it's a new record?

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I believe since you are invoking it via UI page possibly this issue is coming.

Can you share complete script?

Regards
Ankur

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

Nah, not necessary for complete script.  It's easy to test though, just create a new onSubmit client script and a UI Page and mimic the basics.  You'll see, it won't work... well, at least it doesn't for me.

xiaix
Tera Guru

Well, good 'ole DOM manipulation seems to achieve what's needed:

 

Comment out g_form.submit() and call my own function:

 

find_real_file.png

 

And the new function:

 

find_real_file.png

 

Cheesy, eh?  Yep, but when SN forces our hands... we do what we gotta do.  😛

Hey, no worries, there are times when DOM Manipulation is accepted and this use case in using a UI Page is one of them. 🙂

Avoid DOM Manipulation

Avoid Document Object Model (DOM) manipulation if possible. It can cause a maintainability issue when browsers are updated. The only exception is when you are in charge of the DOM: in UI Pages, and the Service Portal.

Instead, use the GlideForm API or consider a different approach for the solution. In general, when using DOM manipulation methods, you have to reference an element in the DOM by id or using a CSS selector. When referencing out-of-box DOM elements, there is a risk that the element ID or placement within the DOM could change thus causing the code to stop working and/or generate errors. It is recommended to review these objects and reduce the use of DOM manipulation methods as much as possible.

 

https://developer.servicenow.com/dev.do#!/guides/paris/now-platform/tpb-guide/client_scripting_techn...