This topic is locked
[SOLVED]

Two events on same page

10/9/2021 10:45:45 AM
PHPRunner General questions
Tandy author

I am stumped.. I have master table and details. I am trying to set 2 event on same page. Here is my code on List page - Before Display:

// ~~TOP CODE~~
// Get the master table data
$master_data = $pageObject->getMasterRecord();
$master_locked = $master_data["locked"];
// Use master table to lock the details table
if ($master_locked == 1){
$pageObject->hideItem("add", $recordId);
$pageObject->hideItem("add");
$pageObject->hideItem("delete", $recordId);
$pageObject->hideItem("delete");
$pageObject->hideItem("update_selected");
$pageObject->hideItem("update_selected", $recordId);
}
//END Lock

// ~~NEXT CODE~~
// Remove ADD Button if Not LOADED
$master_data = $pageObject->getMasterRecord();
$master_load_status = $master_data["load_status"];
if ($master_load_status == "LOADED"){
$pageObject->showItem("add", $recordId);
$pageObject->showItem("add");
}
else{
$pageObject->hideItem("add", $recordId);
$pageObject->hideItem("add");
}
//END Remove Buttons

If I only have the top code only every thing works great. but any of the records that need the //Remove Add Button, Then that is the only code that works and the top code does not work?
So my question is? Can I get both code to work on same page?

Thank for any kind of help I can get on this..
James

Tandy author 10/10/2021

Ok you can only have one getMasterRecord on that page. Least only one works at a time. So what I did is move the Remove ADD Button if Not LOADED code, to List Page: Before Process and now everything works right.

Myr0n 10/15/2021

You have some errors in your code,
1.-
$recordId you can not use in BeforeDisplay because there is not parameter in there, $recordId you can only use in After record processed

2.-$pageObject->getMasterRecord() you can use it 'n' times but i do not recommend it to use it in After record processed just per performance, to solve this, you can use $_SESSION vars, the solution that I propose you is

In list page: Before process add

$_SESSION["master_data"] = $pageObject->getMasterRecord();

in After record processed

// ~~TOP CODE~~
// Get the master table data
$master_data = $_SESSION["master_data"];
$master_locked = $master_data["locked"];
// Use master table to lock the details table
if ($master_locked == 1){
$pageObject->hideItem("add", $recordId);
$pageObject->hideItem("add");
$pageObject->hideItem("delete", $recordId);
$pageObject->hideItem("delete");
$pageObject->hideItem("update_selected");
$pageObject->hideItem("update_selected", $recordId);
}
//END Lock

// ~~NEXT CODE~~
// Remove ADD Button if Not LOADED
$master_data = $_SESSION["master_data"];
$master_load_status = $master_data["load_status"];
if ($master_load_status == "LOADED"){
$pageObject->showItem("add", $recordId);
$pageObject->showItem("add");
}
else{
$pageObject->hideItem("add", $recordId);
$pageObject->hideItem("add");
}
//END Remove Buttons

I hope this help you

Tandy author 10/15/2021

I have tried your code. I guess you still can not call two getMasterRecord on the same page. Even with the $_SESSION..
So I did change to the $_SESSION and how my code looks now:

In List page: Before Process

// Table Sessions
$_SESSION["master_data"] = $pageObject->getMasterRecord();
// End Table Sessions

// Remove ADD Button if Not LOADED
$master_data = $_SESSION["master_data"];
$master_load_status = $master_data["load_status"];
// Use master table to lock the details table
if ($master_load_status == "LOADED"){
$pageObject->showItem("add");
}
else{
$pageObject->hideItem("add");
}
//END Remove Buttons

In Before Display

// Get the master table data
$master_data = $_SESSION["master_data"];
$master_locked = $master_data["locked"];
// Use master table to lock the details table
if ($master_locked == "1"){
$pageObject->hideItem("add");
$pageObject->hideItem("delete");
$pageObject->hideItem("update_selected");
}
//END Lock

I have tried the After Record Processed and the button still show up. I do not know if the code or placing is right but it does work on the site the way I needed it to.

Thank you very much for your help Myr0n