Let's say that you have a suggest box associated with the "selectClient" variable and your SQL query to populate the list of options in the suggest box is:
SELECT CLIENT_ID, CLIENT_NAME FROM CLIENTS
and it returns the following records:
Code: Select all1 | John Smith
2 | Sally Baker
3 | Harold White
4 | Sarah Moore
5 | Mary Deere
Then, you can set the following variable in the trigger before the Dynaform:
And the suggest box will display "Sarah Moore" as the selected option when the Dynaform is loaded.
Then, you can set the following trigger to save to the database after the Dynaform:
Code: Select all$db = '1234567890abcdef1234567890abcdef'; //ID of database connection
$name = addslashes(@@selectClient_label);
$id = @%selectClient; //@% converts from string to integer
$sql = "INSERT INTO SELECTED_CLIENT (CLIENT_ID, CLIENT_NAME) VALUES ($id, '$name')";
executeQuery($sql, $db);
------------------------------------------
If you want to populate a grid from a database query, then you need to create a variable that holds all the options that could appear in the suggest box in any row in the grid.
For example:
Code: Select all$db = '1234567890abcdef1234567890abcdef'; //ID of database connection
//set the list of options in the suggest box in grid:
@=suggestOptions = array();
$aClients = executeQuery("SELECT CLIENT_ID, CLIENT_NAME FROM CLIENTS", $db);
foreach ($aClients as $aClient) {
//CLIENT_ID is the key and CLIENT_NAME is the label for each option in the suggest box:
@=suggestOptions[] = array( $aClient['CLIENT_ID'], $aClient['CLIENT_NAME'] );
}
//set values in grid:
@=clientsGrid = array(
1 => array(
'field1' => 'value1A',
'field2' => 'value2A',
'selectClient' => 3 //label of suggest box in row 1 will be "Harold White"
),
2 => array(
'field1' => 'value1B',
'field2' => 'value2B',
'selectClient' => 1 //label of suggest box in row 2 will be "John Smith"
),
3 => array(
'field1' => 'value1C',
'field2' => 'value2C',
'selectClient' => 4 //label of suggest box in row 3 will be "Sarah Moore"
)
);
Then set the
data variable property of the suggest box in the grid to:
@@suggestOptions