Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Builder - Component to create a new record within modal?

MrRodgers
Tera Contributor

Hi all,

 

I am trying to display a new record in a modal on UI Builder. I want the user to fill in this form. However, I can not identify which component I should select in order to show a new record for a fixed table? I'd appreciate any help. Thanks. 

 

UI Builder - Components.png

Screenshot of some of the UI Builder components.

11 REPLIES 11

I have the same challenge, did you manage to clear the form controller to get a new form after saving it?

 

Hi @Jan Ujcic1 ,

 

To remove the values of form recorded by previously submitted form.

 

We have to refresh the page.

 

1. Replace the data resource  from "Form Controller" to use "Glide Form".

2. Map the sysid ( -1 since new record) and "sections", "fields", "related lists" from "Glide Form" data resource to "Form Default" component.

 

3. All the configurations are same as discussed in the solution of this post.

4. Additional thing we have to do is "Executing Client Script" when form is saved/submitted.

   -- > Client script to refresh the page is given below.

SivaniG_0-1760515870095.png

5. Add this client script to execute in event handler of "Glide From" controller event 

   Event name : Form Submit Completed.

SivaniG_1-1760516025731.png

 

So, here whenever the new record is getting submitted it will loads the page. and removes the saved form values from "Form Default" Component

 

Thank You

Hi SivaniG,

 

thank you, that does work and that option crossed my mind as well but it is a very disruptive solution and isn't acceptable, refreshing the whole page is what we want to avoid when using the modal window for the creation of a new record. 

 

If I open a different record just after creating the first record the "form controller" seems to have flushed and I can create a new record normally. I still haven't figured how to trigger the same process automatically after saving the original new record.

 

Kind regards,

Jan

 

 

Hi @Jan Ujcic1,

 

Thanks for the response.

 

I will try to achieve.

Hi SiavaniG,

 

thanks for the efforts, I did manage to achieve my requirement by basically resetting the client variable to an already existing record and then with a slight delay back to "-1". This mimicked the selection of a record from the list that did reset the controller by default. It turns out that using Glide Form was important in this regard since this trick didn't work with the Form Controller, so thanks! I am would need to dive deeper to understand why this trick works but I'd be happy to learn if someone has an idea.

 

This is the client script that is called on the "Modal closed" event mapping:

 

let existingRecordId = api.data.look_up_existing_record.results[0]["_row_data"]["uniqueValue"] //id of a record fetched by a separate "Look up record" data resource (existing record)
api.setState("selectedRecordId", existingRecordId ); // client state parameter used in Glide Form, defines the form in the modal

helpers.timing.setTimeout(function(){
     console.log("After");
     api.setState("selectedRecordId", "-1");
}, 300);