- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2025 12:18 PM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2025 02:03 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2025 01:22 PM
Hi, its returning all the members because the script isn't resolving. Try this instead.
(function refineQuery(current, parent) {
current.addQuery("account", parent.sys_id);
})(current, parent);
Please mark as helpful or if its resolved the issue, CORRECT!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2025 01:26 PM
Hi Andrew!
I removed the script I had, and just used what you provided. Now, it's not showing any team member records in the related list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2025 01:34 PM
Thats a relatively good start at least its picking up the script.
On the sn_customerservice_case table try using the field name where the account team members are mentioned and use the below.
(function refineQuery(current, parent) {
current.addQuery(<"Account team members field">, parent.sys_id);
})(current, parent);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2025 01:48 PM - edited ‎01-19-2025 01:49 PM
There isn't a team members field on the Case table. When you create a team member, there is an Account field, where the user is added to. The example below, I'm adding Clark Kent as a Sales Representative to 'The Daily Planet' Account. If I go to the The Daily Planet Account record and look at the Account Team Members related list tab, I'll see this record. What I want to do, is create a relationship between the Case table and Account Team Members table, so if a Case is created against the Daily Planet, I want to see the Account Team members related list tab on the Case form, and see that Clark Kent is the Sales Representative for that Account. The like field between the Case table and Account Team Members tables, is the Account field.