Log In    |    Knowledge Base    |    4D Home
Tech Tip: Custom Variables using DAX_DevHook_OnQuery
PRODUCT: 4D Web 2.0 Pack | VERSION: 11.5 | PLATFORM: Mac & Win
Published On: January 25, 2010

Here's a scenario where you may not think of using DAX_DevHook_OnQuery as a solution: You need to send custom variables to the back-end, perform some operations in the database and send custom variables back to the front end. However, DAX_DevHook_OnQuery can prove very useful in this kind of situation.

All you need to do is setup your JavaScript in the front-end to perform a "query" on a table (preferably one not used for queries) in the back-end and send some custom variables. In the back-end using DAX_DevHook_OnQuery detect the table, perform the operation and send some custom variables back to the front-end.

Front-End Code:

// Not a real query, just to receive values from BE
var getValues;

// To get Client information from BE
var client_name;
var client_status;
var client_balance;

// Create a new query in your dax_loginSuccess function:
function dax_loginSuccess() {
getValues= new dax_query('Preferences'); // new query for table Preferences

// Create a function to initiate the query and send the custom variables:
function FEtoBE(){
// pass variables to BE
getValues.addCustomValue('BE_CientID', BE_CientID );

// Create a function to retrieve the custom variables:
function BEtoFE() {
// Retrieve variables from BE
BEInfo = dax_bridge.getCustomLoginValuesFrom4D();
client_name = BEInfo[0].value;
client_status = BEInfo[1].value;
client_balance = BEInfo[2].value;

Back-End Code:

The idea here is to detect the query using DAX_DevHook_OnQuery, get the custom variables, perform any operation on the database and send custom variables back.

  `$1 LONGINT-Table number of the table that gets the Selection
  `$2 POINTER-Pointer to a Longint Array of Table Numbers
  `$3 POINTER-Pointer to a Longint Array of Field Numbers
  `$4 POINTER-Pointer to a Text Array of Values to Query For
  `$5 POINTER-Pointer to a Text Array of Query Comparators
  `$6 POINTER-Pointer to a Text Array of Query Line Links
  `$7 BOOLEAN-Flag: Query in Current Selection†00:00:00†

  `$0 BOOLEAN-Flag: Developer Performed the Query
  `By default the parameters are assigned to local variables as follows:



ARRAY TEXT(customname_at;3)
ARRAY TEXT(customvalue_at;3)


  ` get the name of the table from the passed ID
$tableName_t:=Dax_Dev_Struct_GetNameFromID ($selectionNumber_l)

Case of

: ($tableName_t="Preferences")

$clientID_value_t:=DAX_Dev_GetWebVar ("BE_ClientID")

  `Query the Clients table

READ ONLY([Clients])


Case of

: (Records in selection([Clients])=1)



customvalue_at{1}:="Not found"

End case

  `Send Custom Variable back to Front-End

DAX_Dev_SetCustomVariables (->customname_at;->customvalue_at)

End case