Obtaining existing query in Lookup_Selecting?

In v2018 / v2019 it was possible to obtain the SELECT / WHERE / ORDER details of the lookup currently being processed in the Lookup_Selecting event.Code to modify standard queries could then be generic - avoiding the need to hard-code full query logic within the Lookup_Selecting event, and simply using whatever query had been defined in the project.I’ve been trying to make this work in v2020 so that I can use the example 5 approach to adapt the relevant query, but can’t see how because the existing details don’t seem to be visible within the event.I want to do something like this (example field objects are used to explain the point):if ($fld->Name == “MyLookupField”) {
$select = modifySelect($fld->Lookup->SelectString);
$where = modifyWhere($fld->Lookup->WhereString);
$order = modifyOrder($fld->Lookup->OrderString);
$fld->Lookup->setOptions(ExecuteRows(“{$select} {$where} {$order}”));
}

You may try var_dump($fld->Lookup) to see if you can find what you need. (Press F12 and go to the Network panel to see what you dump.)

I already tried looking there as the help file examples suggest using var_dump($fld->Name, $fld->Lookup, $filter); in the event, but there’s nothing I could see that helps the situation :frowning:

After some more digging, I realised that I can get the SELECT & ORDER BY parts using $fld->Lookup->getSql();Unfortunately, that doesn’t return the WHERE part of the equation - any ideas?

I have a Parent-Child select relationship set up which works in its most basic form - each time the parent select changes, the child lookup shows only records related to the selected client.However, I need to apply additional filtering based on the parent value …but $this->ClientID->CurrentValue, $this->ClientID->EditValue & $this->ClientID->ViewValue all appear to be empty strings / null values.I initially tried setting the lookup filter to:ClientFilter($this->ClientID->CurrentValue)

…as per the help file, but the value passed to the function was empty regardless of the variant I tried.I then attempted to add the filtering using the Lookup_Selecting event, but the encountered the same problem.To double-check the situation, I put the below code in the Lookup_Selecting event and then I’ve checked the text file for the most recently selected client ID to see which variable might hold the answer, but the IDs did not appear anywhere.if ($fld->Name == ‘ClientID’) file_put_contents(‘output.txt’, print_r($Page, TRUE));Has anyone got an answer to this issue?

Adam wrote:
ClientFilter($this->ClientID->CurrentValue)

There is no such code in the help file, it is probably your own code.Be reminded that server events are fired on the server side, CurrentValue/EditValue/ViewValue does not have values in Add pages (there is no record yet). While they have values in the Edit page, the values are on the server side (when the page loads). If you want to get the parent field value that the user changes on the client side (after the page is loaded), try get them from $_POST.

I eventually found a solution - using an updatedone function to track when the parent select was changed, then using the new parent value to get the required records with ajax and replace the option entry that PHPM was creating in the child select.