I am using a grid with a variable table name. It nicely prompts me. But I want to pass in a global table name that is established before the form opens. I tried putting that in onscriptinit and onapplicationinit and it doesn’t seem to be happy with either. It still prompts for the variable table name. What event should have this so it would understand it as that variable?
I’m not sure if I understand the question, because you say you are passing a variable that was already established before the grid opens, but also that you are putting ‘that in the onScriptInit and onApplicationInit’ events.
I assume this is in development, not production, because I don’t think it will prompt for missing variables in production. Are you directly running this grid using the ‘Run’ button, or are you running the form or control that sets the variable and then clicking a link in that application to open the grid?
If you want to directly open the grid in development and don’t want it to prompt for the variable, then in Application → Global Variables, set it as ‘Out’ instead of ‘In’. It shouldn’t prompt for missing ‘Out’ variables. But it sounds like if this variable is not set, the grid won’t have the source table set, so I’m not sure that’s what you want.
In Application → Global Variables, is the variable set as ‘session’ or just as ‘post’ and ‘get’? Depending on how you navigate from the application that sets the variable to the grid that requires it, you might need to use ‘session’.
LOL. Sorry I wasn’t clear. This program does counts from a very large db. 250 mil records or so. When they want to do a new count, they choose from client list and set up a new count. It assigns a count id (sequential). So now they are working with client ABC and count is 12345. When they perform the count, it will write all the relevant records to ABC12345 table. I want to do summaries on this table. Since I know for this count it is ABC12345 I want to pass that table name into a grid and have it use that for the summary. I don’t want the user to have to enter ABC12345 or such. Ideally pass it in a global variable. Was hoping I could set up the sql as select x, y, z from [tabname], but finding that is not at all possible.
I think I understand now, and this should help:
In the SQL tab, enter the global variable and original table names in the ‘Variable for Table’ fields.
I tested something similar to the image below and it seemed to be working. In this example the SQL is “SELECT field1, field2, field3 from original_tablename” and the global variable is [dynamic_tablename]
I found that if I had the query as “… from Original_Tablename” but put “original_tablename” in the ‘Variable for Table’ field, then it ran the default query, so it is case sensitive. When I matched the case, it replaced the table name in with the variable.
I was able to confirm it was working by entering a valid table name where the table didn’t have the listed fields in its structure (for example, ‘table_without_these_fields’). I got an error like ‘Error while accessing the database’ . ‘SelectLimit(SELECT field1 from table_without_these_fields, 12, 0)’. When I entered a table name where the fields did exist, the grid opened and displayed the data.
Aha. It works if I set up the global in a control and call the grid through an application link. It does NOT work if you put the global in any event on the grid bc it has to know what is up BEFORE the grid comes into play. I can make this work. Thanks much!