Lookup_Selecting unable to get value as from $this->Field->CurrentValue

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
innovativeshadow
User
Posts: 86
Location: Almaty, Kazakhstan

Lookup_Selecting unable to get value as from $this->Field->CurrentValue

Post by innovativeshadow »

Hi all,

A little help please:

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter)
{
    // var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
    // Enter your code here
    if ($this->PageID == "edit" && $this->Status->CurrentValue == 'U' ) {
    if ($fld->Name == "Status") {
        $fld->Lookup->setOptions([
            ["U", "...", "", "", ""],
            ["K", "To Manager", "", "", ""]
        ]); }
 } else if ($this->PageID == "edit" && $this->Status->CurrentValue == 'K' ) {
     if ($fld->Name == "Status") {
        $fld->Lookup->setOptions([
            ["K", "...", "", "", ""],
            ["U", "Revoke", "", "", ""]
        ]); }
    }
}

The above code is not working because the $this->Status->CurrentValue is giving null value.


innovativeshadow
User
Posts: 86
Location: Almaty, Kazakhstan

Post by innovativeshadow »

Well after searching for a while got a solution from other posts.

Make a session variable of the value in Row_Rendered:

// Row Rendered event
function Row_Rendered() {
$tStatus = $this->Status->CurrentValue;
    $_SESSION['t_status'] = "$tStatus";
}

Use it in the Lookup_Selecting as

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter)
{
// var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
// Enter your code here
if ($this->PageID == "edit" && $_SESSION['t_status'] == 'U' ) {
if ($fld->Name == "Status") {
$fld->Lookup->setOptions([
["U", "...", "", "", ""],
["K", "To Manager", "", "", ""]
]); }
} else if ($this->PageID == "edit" &&$_SESSION['t_status'] == 'K' ) {
if ($fld->Name == "Status") {
$fld->Lookup->setOptions([
["K", "...", "", "", ""],
["U", "Revoke", "", "", ""]
]); }
}
}

Hope this helps someone


innovativeshadow
User
Posts: 86
Location: Almaty, Kazakhstan

Post by innovativeshadow »

Not working as expected though.

We have to double open the Edit window to get the options set.


arbei
User
Posts: 9284

Post by arbei »

Note that server event is run on the server side before the page is sent to the browser, $this->Status->CurrentValue does not have value in Add page. Your code will only work in Edit/Copy page for record with value stored in the "Status" field previously. If you set lookup options manually, you need to handle the case where Status is empty.


mobhar
User
Posts: 11660

Post by mobhar »

Perhaps you may try Ajax by API and Client Scripts.


Post Reply