How to add a record to a LookupQuery without leaving the current form?

Hello, I have a form named “File” with a field named “Representative” that is a display type _LookupQuery. This field is mandatory.

The user must select a representative, but if it doesn’t exist, the user must cancel the creation of the File, go to the representative form, create a representative, then come back to the File form. He has to start the File again to find the Representative he just created.

Is there a way to add a button somewhere in the File form called “Create a representative”? Clicking this button would open the representative form. When completed, this form is closed and the user is back to the File form so he can find the Representative just created.

Thanks for your help!

Hi Jean,

Thank you for your question.

The scenarios you described are not supported, as once you begin entering data into a form, you cannot leave it unless you either save the record or cancel the creation process (which would result in losing the entered data).

As an alternative, I suggest the following approach:
You could include an additional result in your query, such as “Data not available yet” (or any label you prefer). This would allow you to complete the creation of the File record, then navigate to the Representative form to add the new representative record. After that, you can return to the File form and simply update the Representative field with the newly created record.

This approach can save time and effort, as you won’t need to re-enter all the values in the File form—only the Representative field will need to be updated.

You can further enhance this solution by adding a button to the File form (no additional field is required in the table). This button would be displayed only when:

  • The Representative field is set to “Data not available yet”.

When clicked, the button could use the selectAction() method to automatically navigate to the Representative form to create a new record. After saving, you could use SelectAction() with the record parameter to return to the specific File record and update the Representative field with the newly created representative.

Using this approach, the new button will be displayed whenever the Representative field has the value “Data not available yet”, making it convenient to add the Representative record at a later time.

Please let me know whether this solution works for you.

Regards,

Elton S

Hi Elton, thank you for your quick answer! That seems like a satisfactory solution. I’ll try it and let you know how it goes. Thank you very much.

Regards,

Jean

Hello,
I tried to implement the proposed solution for adding a record from another form, but I am unable to make the full flow work.

AddRecordToLUp-20260201-194517762991885.fdf (3.4 MB)

For simplification the Representative field is optional.

1- When the user clicks the blue “+” button, I call the function OpenRepresentativeForm (Event On Click).
function OpenRepresentativeForm(five, context, result) {
five.setVariable(“CurrentFileKey”, five.field.FileKey);
five.selectAction(“Representatives”);
return five.success(result);
}
Problem: When the File form is in create mode, the FileKey is not yet generated, so CurrentFileKey is null. Is there any way to automatically save the Files form in this function?

2- When I call five.selectAction(“Representatives”), the list view is displayed and the user must click the yellow “+” button.
Is there a way to directly open the Representatives form in create mode ?
Something like selectRecord() that would open the form fullscreen, so the user doesn’t need to click the yellow plus button.

3- After the new Representative record is created, I want to return to the File record and pre-fill the Representative field. I call the BackToFileForm function called on th Event “On Complete”.
function BackToFileForm(five, context, result) {
five.setVariable(“CurrentRepresentativeKey”, five.field.RepresentativeKey);
five.selectAction(“Files”, five.getVariable(“CurrentFileKey”));
return five.success(result);
}
but the variable “CurrentRepresentativeKey” is always empty. I tried different types of event with no success.
Can I use the same function to set the CurrentRepresentativeKey in the five.field.RepresentativeKey ?

4- If the user opens the Representatives form with the side menu, they will then bring to the Files form. Is there a way to prevent this or should I create a clone of the Representatives form without the function that brings the user back to Files form ?

This feature is very important for my application, and I would love to know the recommended way to implement this workflow.

I joined the fdf of my sample application.

Thank you!

Hi Jean,

Thank you for sharing the application sample. Below are the details of the workflow.**

Form and Field Updates**

  • Add a record “Representative not available yet” to the Representative form (This step will be optional as explained at the end of this comment).

  • In the Form File, add a Show If condition to the AddRepresentative field, so it is displayed only when RepresentativeKey has the value “Representative not available yet”.

    • In my example, the condition is:
      (five.isCreate() == false)
  • (Optional) In the Form File, remove the FileKey field from the form. There is no need to expose this key, as Five will manage it automatically for the Wizard table.

Function Updates

  • In the function OpenRepresentativeForm, set the variable CurrentFileKey using:
    five.form.Files[‘File.FileKey’]

  • In the function BackToFileForm, clear the variable after calling selectAction:
    five.clearVariable(‘CurrentFileKey’);

  • In the Representatives form, remove the function BackToFileForm from the On Complete event.

New Navigation Field

  • Add a new field (no database binding) called “Back to the File Form” with a Button as the display type.

    • In the Tab Display Types, apply the following Show If condition:
      (five.isCreate() == false && five.getVariable(“CurrentFileKey”) !== “”)

    • In the Events tab, attach the function BackToFileForm to the OnClick event.

Resulting Workflow

With these changes, the workflow will be as follows:

  1. Create a new File, select “Representative not available yet”, and save the form. The “+” button will then be displayed.

  2. Click the “+” button to open the Representative form, add a new record, and save it. The “Back to the File Form” button will appear.

  3. Click “Back to the File Form”. The previous File record will automatically reload, allowing you to select the newly created Representative.

Notes

  • The “+” button is displayed only when the form is saved. This ensures there is a valid record to return to.

  • The “Back to the File Form” button is displayed only when:

    • The record is saved, and

    • The Five variable CurrentFileKey exists.
      This guarantees the button is shown only when navigating back to a previously selected File.

Optional Enhancement

You do not strictly need to add the “Representative not available yet” record to the Representative form. It is primarily a user-friendly indicator that the information has not yet been completed.

If desired, you can also make this value the default for new File records:

  1. In all environments, add the record “Representative not available yet” to the Representative form.

  2. Create a query to update this record with a unique GUID shared across all environments.

  3. Create an Admin-only process to run this query (this needs to be executed only once per environment).

  4. Set the updated key of “Representative not available yet” as the default value for RepresentativeKey in the Form File. This way, whenever you (as Admin) create a new File record, this value will be selected by default.

When running the application for each environment, you must create a representative record named “Representative not available yet” and run the process so that only the admin has access to it. Everything should be ready for this enhancement.

I have attached the updated file with my changes, which also includes all additional features. With this, I believe the workflow is now complete.

Please, let me know how it goes.
Regards,

Elton S

AddRecordToLUp-AddingRecordWithoutLeavingCurrentForm_ForJean.fdf (3.4 MB)

Hello Elton, thank you for your explanations and the fdf file. It won’t be as automatic as i would have liked for the user, but it is much better that the previous situation.
Regards, Jean.