Change setOptions using Ajax

Good Day! Is it possible to change to setOptions of Lookup using Ajax?

For Example:

I have field gender. When the use select “Male”, the Lookup will display males individual from the target table.

You may use Dynamic Selection Lists.

I use dynamic screen. But my code located at Lookup_Selecting events override the setting in the dynamic selection list

You may post your code for discussion.

Here is my lookup settings:

Table: tbl_finalist

lookup Field : cand_id
Parent Field: gender
Filter Field: sex

  • The code above is working properly. Cand_id is filtered according to gender.
    But when I put the ff code in the Lookup_Selecting, the filter is not working, it seems it was overridden.
function Lookup_Selecting($fld, &$filter)
{
  
    if ($fld->Name == "cand_id")
    {

        $poid = $_GET["fk_id"];

	if(CurrentPageID()=='add')
	{ $fld->Lookup->setOptions(ExecuteRows("Select id,  candidate_no, candidate_name from tbl_candidates where eliminated  ='No' and id not in  (Select cand_id from tbl_finalist    where portion_id = '$poid')  order by gender desc,  display_order asc"));  }
	
   }

}

Notet that there is no $_GET["fk_id"] in Ajax request when gender is selected. You may press F12 in your browser, go to the Network panel to check the looup request, the data sent can be checked in the Payload.