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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 10:42 AM
I have an onSubmit client script on the Incident table that invokes a GlideModal:
This works great.
Now, in the UI Page that this GlideModal is invoking has this bit of code:
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:
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 10:59 AM
Hi,
I believe since you are invoking it via UI page possibly this issue is coming.
Can you share complete script?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 11:08 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 11:05 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 11:21 AM
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.