Apply filter based on other field value

I would like for a filter applied under the lookup table to only work based on a value of another field.

Ex.

Field: Approval

Field: Approved_By (filtered here under the Lookup table)

If Approval is different than value 2 I like for the filter to be applied. But if Approval = 2 then filter should be disable.

What modification I need to do to the filter?

Here is the filter:

(CurrentPageID() == “add” || CurrentPageID() == “edit”) ? "ContID= " . CurrentUserID() . “” : “”

Put this code in “Lookup_Selecting” server event, and then re-generate ALL the script files, and try again:

if (CurrentPageID() == “add” || CurrentPageID() == “edit”) {
if ($fld->Name == “Approved_By”) {
if (!empty($this->Approval->CurrentValue) && $this->Approval->CurrentValue != “2”) {
AddFilter($filter, "ContID= " . CurrentUserID());
}
}
}

That didn’t work but I have another idea.

Instead of applying a filter to a drop-down field ‘Approved_by’, can we make the field ‘Approved_by’ hidden (only on Edit) and save it to the table with the CurrentUserID just IF that user changes the other field Approval to Approved?

Both field are in the same table.

EX.
Only while editing, NOT on Add.

Field: Approval - Logged in user changes this field to Approved (value 2)
Hidden Field: Approved_by - Takes the value of the CurrentUserID() and saves it to table

Thanks

napiedra wrote:

can we make the field ‘Approved_by’ hidden (only on Edit) and save it to the table
with the CurrentUserID just IF that user changes the other field Approval to Approved?

Yes you can. You may hide the field by using “Page_Load” server event, and then use “Row_Updating” server event to assign that field, for example:

In Page_Load:
$this->Approved_by->Visible = FALSE;

In Row_Updating:
$rsnew[“Approved_by”] = CurrentUserID();