Access form elements in UI Page displayed in modal

JAmos
Tera Expert

I have a UI Action button which launches a GlideModal dialog, the content of which is a UI Page.  This UI Page takes the user through a brief flow to get to some related data.  Initially, there is a simple select input, the onchange handler makes a GlideAjax call to retrieve some data server-side (it actually comes from a REST endpoint on another system, but the Script Include handles that part).  That data populates a second select input, choice is made, stuff is done, and the user gets the final result.  I'll paste a simplified example below to help illustrate.

 

My question is: what is the proper way to access the form and form elements in my UI Page in order to carry out these functions, display appropriate messages (both form and field level), etc.?  g_form is available in the Client Script, but it seems to be a reference to the form on the containing page (a Task record in this case) where the UI Action button resides.  Is Javascript DOM manipulation the only way to go about this?  If I can't use g_form, is there any way to accomplish some of the functionality normally provided, for instance showFieldMsg()?

 

Here's the script for the UI Action that launches the UI Page in a GlideModal dialog:

JAmos_0-1681298763374.png

 

And this is the HTML and Client Script for the UI Page:

JAmos_1-1681298850899.png

 

It's entirely possible that I'm using the wrong types of components / controls, so if there's a better way to go at this, I'm open to suggestions!

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage

Hello

 

I have used DOM manipulation in UI pages, as I also did not find any other way (at least when I was working on similar requirement). I see OOTB popups containing UI page also uses DOM manipulation. 

 

As the UI page is our custom and we are defining the HTML elements name/tags/class it should be ok to use DOM manipulation.

 

We should not be using DOM manipulation in normal record form or anywhere else as ServiceNow can update DOM structure in upcoming upgrades to accommodate new feature/fix.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

2 REPLIES 2

Ahmmed Ali
Mega Sage

Hello

 

I have used DOM manipulation in UI pages, as I also did not find any other way (at least when I was working on similar requirement). I see OOTB popups containing UI page also uses DOM manipulation. 

 

As the UI page is our custom and we are defining the HTML elements name/tags/class it should be ok to use DOM manipulation.

 

We should not be using DOM manipulation in normal record form or anywhere else as ServiceNow can update DOM structure in upcoming upgrades to accommodate new feature/fix.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Thanks, Ali.  I'd seen several things cautioning about using DOM manipulation, and that makes sense when working with normal records since it's possible for those fields to change and stuff.  As you explained though, with the custom UI Page, we have control over the structure and naming of elements, so it should be a safe approach.

 

It's still unfortunate that there isn't a way to get a handle for the form to leverage some of the features of GlideForm, but it is what it is.

 

Thank you for the reply and explanation!