New Relationship / Related List

MStritt
Tera Guru

There is a related list on the account table called Account Team Members [sn_customerservice_team_members]. I want to add this related list to the Case table/form [sn_customerservice_case]. I have created a new relationship between these 2 tables. The relationship I created shows 'Applies to table' as [sn_customerservice_case], and 'Queried from table' is [sn_customerservice_team_member]. I've added it to the Case form as a related list. On a Case that's associated/opened against the Account that has the team member records, I'm seeing all team member records from all Accounts, and not just the team members created against the Account the Case is created against. Why am I seeing all team member records against all Accounts, and not just the ones created against the Case Account? Below is the Relationship 'Query with' script:

(function execute(/* GlideRecord */ current) {
    if (!current.account) {
        return null; // No account, no related records
    }

    var teamMembers = new GlideRecord('sn_customerservice_team_member');
    teamMembers.addQuery('account', current.account); // Match the account
    teamMembers.query();
    return teamMembers; // Return filtered records
})(current);

 

1 ACCEPTED SOLUTION

Hi @MStritt 

Okay, in that case try this one...

(function refineQuery(current, parent) {
    // Ensure the 'account' field from the parent case matches the 'account' field in the account team members table
    current.addQuery("account", parent.account);
})(current, parent);

View solution in original post

7 REPLIES 7

Hi @MStritt 

Okay, in that case try this one...

(function refineQuery(current, parent) {
    // Ensure the 'account' field from the parent case matches the 'account' field in the account team members table
    current.addQuery("account", parent.account);
})(current, parent);

That did it. Thanks!

You're welcome! Glad its sorted.