Filter detail view

I'm attempting to filter a detail view in the preview list using a foreign key in recordsSelecting phpmaker 2026:

    if (Get("fk_league_id") !== NULL) { 
       AddFilter($filter, "contact_priority = (
            SELECT MAX(vc2.contact_priority)
            FROM view_contacts vc2
            WHERE vc2.club_id = " . Get("fk_away_club_id") . ")"); // Add your own filter expression


     }
     var_dump($filter,Get("fk_league_id"),Get("fk_away_club_id"));
 

league_id and away_club_id are used in master view to link to league_id and club_in detail table but are shown as NULL. Can you help?

I couldn't find how to extract the keys from the master View record, but in the end extracted them from the filter in the detail Preview server event:

    public function recordsSelecting(&$filter): void
{
// Extract club_id and league_id from the incoming filter
    if (!preg_match('/`club_id`\s*=\s*(\d+)/', $filter, $m1)) {
        return; // Not in preview context
    }

    $clubId = $m1[1];

    // Extract league_id if present (not strictly needed)
    $leagueId = null;
    if (preg_match('/`league_id`\s*=\s*(\d+)/', $filter, $m2)) {
        $leagueId = $m2[1];
    }
...........

I'd still be interested to learn if there's a cleaner, more direct way.