This topic is locked

Filter lookup in detail table

10/30/2013 1:39:19 PM
PHPRunner General questions
romaldus author

PHPRUNNER 6.2

In a master detail "add page" :

How I filter lookup in detail table based on a value of a field in master table?


Sales (master table)

SALES_ID, WAREHOUSE, SALES_DATE
Sales_Details (detail table)

DETAIL_ID, SALES_ID, ITEM_ID


WAREHOUSE field in master table is a lookup field where i can choose a warehouse
ITEM_ID field in detail table is also a lookup field where i can choose items from database based on the WAREHOUSE selected in master table (different warehouse, different items available)
I tried to add a where clause:
"WAREHOUSE='"._SESSION["WAREHOUSE"]."'"
but didn't work.

Sergey Kornilov admin 11/1/2013

This is would not work for two reasons.

  1. Syntax is incorrect, here is the corrected one

"WAREHOUSE='".$_SESSION["WAREHOUSE"]."'"


2. You need to populate $_SESSION["WAREHOUSE"] variable manually on the page load. You need to execute a SQL query that retrieves data from the master record and save the value of WAREHOUSE field to $_SESSION["WAREHOUSE"] variable.

romaldus author 11/6/2013



This is would not work for two reasons.

  1. Syntax is incorrect, here is the corrected one

"WAREHOUSE='".$_SESSION["WAREHOUSE"]."'"


2. You need to populate $_SESSION["WAREHOUSE"] variable manually on the page load. You need to execute a SQL query that retrieves data from the master record and save the value of WAREHOUSE field to $_SESSION["WAREHOUSE"] variable.


what do you mean with "on the page load"? In Sales_Details add page (and all other add pages) events there are only "Add Page:before process" , "copy page : Onload" ..... etc

Sergey Kornilov admin 11/6/2013

Yes, BeforeProcess event will work. The idea is to make sure this session variable is populated before dropdown box is created.

romaldus author 11/6/2013



Yes, BeforeProcess event will work. The idea is to make sure this session variable is populated before dropdown box is created.


I have tried using the following code in add page Before Display :

$rstmp = CustomQuery("select WAREHOUSE from MASTER_ITEMS where WAREHOUSE='".$_SESSION["WAREHOUSE"]."'");

$datatmp = db_fetch_array($rstmp);

$_SESSION["CustomWarehouse"] = $datatmp["WAREHOUSE"];


and in where clause

"CustomWarehouse='"._SESSION["WAREHOUSE"]."'"


[size="4"]This custom code works fine in PHPRUNNER :[/size]


[size="4"]But in PHPRUNNER generated app, detail table became Disabled :[/size]

Sergey Kornilov admin 11/7/2013

PHPRunner's 'Test it' button doesn't take session variables into account, session variables only exist when you run your application in the browser.
There is most likely an error in your PHP code that prevents detail table from working properly. In your code you keep referring to $_SESSION["WAREHOUSE"] variable. You need to make sure this variable is not empty so SQL query works as expected.