Reset form controller in ui builder

angeloorteg
Tera Contributor

 

Hi everyone.

 

I have a modal with a form using a form controller .

 

After saving (create) the first time - it is linked to this record, no matter what I do.

 

The isNew flag of the form controller remains false from that moment on...

 

I tried resetting the sysId, reloading the form, refreshing it - it will stay in this state unless I refresh the page.

 

I want it to be a create modal only …

I appreciate any help, need to get this fixed since people might not notice that they are updating the previously created record 😕

 

If you need screenshots or any more information let me know - I am really lost rn

4 REPLIES 4

angeloorteg
Tera Contributor

--- delete

angeloorteg
Tera Contributor

UPDATE

 

I made it partially work. 


I have a client var newRecordId = -1  to tell the form I want to create a new record.

Once a record is created, I tried to setting it back to -1 but it didnt quite fire an event change.


So what I do now, on after create on [Form Completed] Event I set it to the newly created sysId, and then on [Modal close] Event I set it back to -1. 

This triggers an event change and isNew-Flag is back to true.

 

The problem now is, it works on first creation and seems to be okay ( but throws a canvas error in console ).
On the second creation it will open a blank page. Both are created. 
Why that? The first console error states thats it cant find a value for generating the route to navigate to. 
The second creation then, seems to be using a fallback route opening a blank page. 

So how to fix that?
I created a new UI Action, hoping that I can save and close the modal as intended :

current.insert();
action.setRedirectURL(current);
gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);


Now - a new Problem - the errors in console are gone, and the blank page is a real record opening within the same tab. 
So basically it works fine now - but navigates me away from the parent form where I want to use the Create Button to open the modal n-times and create more records. 


Is there a way to prevent it from navigating away from that page - or maybe to at least open the record in a new tab? ( Probably hard, because the modal is part of the current page)

I just want to have a modal with a form and formcontroller to create new appointments,  never update them in the form and never be redirected anywhere, just close the modal after creation.

Help 

David Speirs
Tera Contributor

Did you ever figure this out? Running in to the same issue currently.

Yes I made it work for me.

 

For the general setup:
I basically use 2 client state params,
formValid (check if form valid) and newRecordId (pre-set with -1 for new record) - to track the current record. 

 

================== FormController =====================

 

angeloorteg_2-1769149642457.png

 

And set the settings accordingly - MOST IMPORTANT 

I deselected all, that I didnt really need. 

The biggest issues on my side was that  "Is mapped to app shell" was checked, so the controller thought it's the actual page and tried to redirect and stuff.

 

 

angeloorteg_11-1769150825422.png

 

On the FormController Events add the following...

The two refreshs are just the datasources to display the new data

 

angeloorteg_6-1769150110913.png

 

 

[Form] Form submit completed -> Set client state parameter 
angeloorteg_0-1769149513528.png

[Form] Form submit completed -> Open or close modal dialog

angeloorteg_1-1769149613728.png

 

[Form] Validate form failed -> Set client state parameter

angeloorteg_7-1769150262490.png

 

 [Form] Validate form succeeded-> Set client state parameter

angeloorteg_8-1769150298467.png

 

 

 

================== THE CREATE TRIGGER (Button or whatever)=====================

 

On the create call I basically just open the modal... 

The script is setting some params in the form and has some console logs...

 

angeloorteg_9-1769150477227.png

Grid clicked for new event -> Client Script Create Appointment (optional)

 ...

   console.log(`Form controller`);
    console.log(`Is new: ${api.data.create_form_controller.isNew}`);
   
    console.log(api.data.create_form_controller.sysId);
   
    api.data.create_form_controller.clearFieldValue({fieldName: "subject"});
    api.data.create_form_controller.setUserValue({fieldName: "start", value: startFormatted});
    api.data.create_form_controller.setUserValue({fieldName: "end", value: endFormatted});
    api.data.create_form_controller.setUserValue({fieldName: "to_users", value: userId});
    api.data.create_form_controller.removeAllFormMessages();
    console.log(`recordId: ${api.state.newRecordId}`);
 ...

 

Grid clicked for new event -> Open or close modal dialog 

angeloorteg_10-1769150677788.png

 

 

================== MODAL Dialog =====================

 

On the modal just reset the newRecordId to -1 when the modal is closed to make sure we have a new record here.

 

 

angeloorteg_3-1769149726270.png

 

================== SAVE/CREATE BUTTON  =====================

 

On the save button - I ask the form to validate and set my formValid state param, 

and then just execute the Save Action.

 

 

angeloorteg_4-1769149799234.png

 

 

Let me know if you have more questions 🙂