Insert detail with master id - mix of master id when using global variable

I’m sure I can’t be the first to face this issue, but I’ve been searching for a solution for weeks and have found absolutely nothing.
Here is the situation, very basic description:

  • my main App is a grid with client info (let’s say “client_id”, “cli_name”, “cli_birthdate”, …)
  • I created an application link to open a From Application that contains several tabs (this is a Form Application with Master-Details where each detail is in a block that is defined as a tab in the Layout). Let’s call this Form app “ClientEditForm”.
  • from the main grid app, I pass the “client_id” to the ClientEditForm through a global variable defined as “input” named “[glo_client_id]”.
  • in the ClientEditForm, one of the tab is the addresses of the client. This is a grid with several addresses for the client. To open this Grid app, it’s done throught the master-detail feature from ClientEditForm and I pass along the “client_id” through another global named “[glo_client_id_add]”.
  • So at this point, the addresses grid has a SQL with a “WHERE add_client_id = [glo_client_id_add]” which works perfectly fine.
  • From this addresses grid, I can use the “Edit” feature (application link) to open the Address From applciation to update an address. This works perfectly fine too because the link is based on the record row and the “add_client_id” is passed to the form.
  • In the Address Form, in the “OnLoad” event, I have the following code to handle the INSERT. This works perfectly fine too IF I OPEN ONLY ONE CLIENT AT A TIME.
    if ({address_id} > 0) {
    // EDIT MODE
    } else {
    {add_client_id} = [prm_client_id_add_frm];
  • Now let me expalin the issue. From the Main Grid app (grid with client info), I open the client #1. This opens a new Form in my Menu App and I can open the Addresses Tab.
  • I now open client #2 from the main grid app and I also go into the Addresses tab.
  • Right now, the [glo_client_id_add] global variable is set to “2” because the last tab I open was the one of client #2
  • If I go back to client #1 and I click the “Insert” button, the code mentioned above in the “OnLoad” event will take the id of client #2 to perform the INSERT. What a mess.
  1. I know about GLOBAL variables. They are shared between all applications
  2. I know about ATTRIBUTES variables. They are shared between all instances of the same application.
  3. I haven’t found anything about variables that are local to one instance of an application, which would solve this issue.
    SO MY QUESTION IS: how do you guys have solved this big issue?

your problem is in the on load, because the variable will always take the last ID. I advise you to make your global variable an array() so you know what you are doing with each ID and you will keep all the selected ones.

I think you must create a new record for each new client into other tables. so you don´t need use variables.

1 Like

Hi Guys. Thanks for taking the time to answer.

Rodattoni: I understand the idea of keeping all the “clients” ID. Everytime I open a new client tab, I can save its ID in an array. So far so good. The issue rises when I go back to a previously opened tab ! How can I know which ID it is ???

Algavar: I thought about this (using a table with IDs). The issue is the same as mentioned above. When I go back to a previously opened tab (click on a tab), how can I know which ID it is?

I can save the IDs anywhere (array, table), the problem is always the same. I get the ID of the client from the main clients grid. From here, I can open the client tab by passing the ID from the main clients grid to the client application (displayed as a tab) and have several clients opened at the same time (this feature is absolutely mandatory). When the client tabs are opened, I need to switch from one to another.

Here is an example:

  • From the main clients grid, I click on the client ID 34
  • The client tab 34 is opened ([glo_client_id] is 34)
  • I go back to the main clients grid and click on client ID 78
  • The client tab 78 is opened ([glo_client_id] is 78)
  • I go back to tab of client 34
  • I go on its detail (addresses grid) In grid application, there is no way to store anything but rows.
  • from the grid, I click on “Add” and the “Address Form Application” is displayed

PROBLEM TO SOLVE: at this point [glo_client_id] is 78 and the current client is 34. Let’s presume I have saved the ID 34 when I initially opened its tab (in an array or a table), how can I retrieve it ? Searching for it would mean kowing it :rofl:

I’m always getting to the same point … THANKS A LOT FOR HELPING ME finding a solution.