Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

count #each results

(0) ShareShare
ReportReport
Posted on by 386

Hi

do you know if you can count the results of a query in the marketing email ?

example below:

<p>You have purchased:</p> <ul>

<!-- {{#each contact.contact_product_productid}} -->

<li>{{this.name}}</li>

<!-- {{/each}} --> </ul>

some group by can have 3 results other 10 etc

do you know which function/method for "this" obj can be use to give you the results count ?

 

thank you

  • slx Profile Picture
    slx 386 on at
    RE: count #each results

    Thank you, as this is javascript / html I though there is a way to count {{this.xxx}} results and add further personalization based on results (if 1 or more)

    I am new to marketing stuff but familiar with dynamics. I try to describe a strange limitation below:

    1) we build segments and apply the query block for a subset of data, let's say target only contacts for products with product type = xxx

    2) the segments contain contacts only (not all contacts but the contacts from 1)

    3) when segment is used in a customer journey and sending a marketing email for contacts, for the iteration [tag:each] it's not possible to get the subset of data it will list all associated records (not possible to get only products with type =xxx unless hardcoded in the email body js/html)

    4) the workaround found was to use an intermediary entity to keep the query block results and then use this in [tag:each] query but not sure if there is any solution out of the box

    kind regards

  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    RE: count #each results

    Hi slx,

    Unfortunately, you can't count query results directly in marketing emails, there is no OOB function to do so currently.

    It is recommended to create a custom field that type is rollup in Contact entity, which records the count of products.

    pastedimage1667871876624v2.png

    Edit it as the following screenshot.

    pastedimage1667871792437v1.png

    Note: The default recurrence of the rollup calculation is 1 hour. You can change this with following steps:

    1. Navigating to Settings > System Jobs
    2. Select view "All Rollup Field Calculation Jobs"
    3. Select and Open the job with name "Calculate rollup fields for <your entity schema name> entity.
    4. In the job window, on the command bar, click Actions > Modify Recurrence.

    Then you can use the following code into the marketing email to show the number of related products:

    {{contact.new_countofproducts}}

    Result:

    pastedimage1667879089325v3.jpeg

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans