web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Retrieve the latest date from items in an each loop

(0) ShareShare
ReportReport
Posted on by 10

Hi! 

This issue regards HTML when designing a marketing email.

I am trying to get a startdate from an entity called "Membership" by using an #each loop. 

I prefer c# but sometimes these tasks appear as well. What I would've done in c# is basically like this (code not tested):


DateTime startDate = new DateTime();
DateTime endDate = new DateTime();

foreach(var membership in memberships)
{
    if(membership.startdate > startDate)
    {
        startDate = membership.startDate;
        endDate = membership.endDate;
    }
}


And then print out the variables.
Doing the same in html doesn't seem to be as easy.
Below code is insufficient, and I don't know how to use variables like this.

 

var startDate = ?;
var endDate = ?;

{{#each contact.membership_id}}
    {{#if (gt this.startDate startDate)}}
        startDate = this.startDate;
        endDate = this.endDate;
    {{/if}}
{{/each}}

Member from:{startDate}

Member to:{endDate}

Please help me understand if and how this is do-able.

Another thought I had was to make a list with all the startdates and enddates (a list<datetime, datetime>-ish) and then choose the max datetime among all entries. But I have no clue on how to do this either. 

Best regards,
Matilda

I have the same question (0)
  • Verified answer
    Nya Profile Picture
    29,060 on at

    Hi Matilda,

    The C# code is not supported in the code block of Marketing Emails.

    It is recommended to create a custom field in your entity, which can record the latest date with something like workflow. Then insert the field as a dynamic content into the email, so that the latest date can be shown.

     

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

  • Matilda Olsson Profile Picture
    10 on at

    Yeah, we thought of solutions including a new field, a parameter to the workflow or customer journey, but we are unfortunately not allowed to do any such changes.

    I understood it the same way, that C# was not apply-able to the HTML. But there are no other ways in HTML to use variables or lists the way I want then? If not then I will just have to accept defeat.

    Thank you for the fast answer!

    Best regards,

    Matilda

  • Elisa del valle Profile Picture
    10 on at

    I have the same question,  could we use variables en [tag:each] loop

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans