Page 1 of 1

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

Posted: Wed Mar 15, 2023 11:34 pm
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.


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

Posted: Thu Mar 16, 2023 12:02 am
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


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

Posted: Thu Mar 16, 2023 1:29 am
by innovativeshadow

Not working as expected though.

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


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

Posted: Thu Mar 16, 2023 8:52 am
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.


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

Posted: Thu Mar 16, 2023 8:53 am
by mobhar

Perhaps you may try Ajax by API and Client Scripts.