Skip to main content
vikrantb276354
February 19, 2025
Question

Unable to use Aggregation on CDT fields with many-to-many relationship.

  • February 19, 2025
  • 2 replies
  • 0 views

Hi,

Am unable to use aggregate functions on child CDT having many to many relationships with parent CDT.

Background

I have a parent CDT called Campaign which has many to many relationship with child CDT called Channel. I have Campaign table, Channel table and mapping table as well to hold the relationship in database.

Requirement

I need to group the Campaigns based on Channels.

Issue

I am unable to use Aggregate functions on channels field in my Parent CDT - Campaign.

How can I achieve this using CDT relationships.

Thanks

 

2 replies

February 21, 2025

first create the mapping table on both campaigns and channels 

then Create a query rule to fetch the required data from campaigns associated with channels 

a!queryEntity(
entity: cons!YOUR_CAMPAIGN_ENTITY,
filters: a!queryFilter(
field: "id",
operator: "IN",
value: ri!campaignIds
),
query: a!query(
pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100),
selection: a!querySelection(columns: {"id", "campaignName", "channel.id", "channel.channelName"}),
filters: a!queryFilter(
field: "channel.id",
operator: "IS NOT NULL",
value: ri!channelId
)
)
)

Once you retrieve the campaigns and associated channels, you can group the campaigns by their channel

i hope this will use 

vikrantb276354
February 21, 2025

Thanks for your reply.

We already have a mapping table between campaign and marketing channel to store the many to many relationship.

Even filtering on channel value is not working.

Code:

a!localVariables(
local!data:
a!queryEntity(
entity: cons!MSS_ENTITY_CAMPAIGN_REQUEST,
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "AND",
filters: {
a!queryFilter(
field: "marketingChannels.value",
operator: "in",
value: ri!channel
)
},
ignoreFiltersWithEmptyValues: true
),
pagingInfo: ri!pagingInfo
),
fetchTotalCount: true
),
local!data
)

Error:  

Expression evaluation error at function a!queryEntity [line 3]: Cannot filter by field [marketingChannels.value] because it is a complex, multiple, or child of a multiple data type.

Thanks