Skip to main content

Notifications

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

Retrive a field on a lookup from a loop item (this.lookup.field)

(0) ShareShare
ReportReport
Posted on by 10

Hey! 

This post is about marketing emails design, html and each loops.

I am trying to figure out how to retrieve a field from a lookup field.

Code below explained: 

  • Iterate through all memberships on a contact
  • See if the membership is a main membership
  • See if the statuscode is 1
  • See if reason.code is not equal to 7 or 6
  • If all of the if:s above, print enddate.

{{#each contact.membership_id}}
	{{#if (this.main_membership_id.is_main_membership)}} //This is a lookup field on membership (1:N). I want to get the value of the bool is_main_membership.
		{{#if (ne this.statuscode 1)}}
			{{#if (ne this.reason_id.code 7)}} //Same as the first if statement. I want to reach the field on the lookup field.
				{{#if (ne this.reason_id.code 6)}} //Same as the row above

                    

End date: {{this.enddate}}

{{/if}} {{/if}} {{/if}} {{/if}} {{/each}}

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

Best regards,
Matilda

  • Matilda Olsson Profile Picture
    Matilda Olsson 10 on at
    RE: Retrive a field on a lookup from a loop item (this.lookup.field)

    Thank you Nya for your answer! I will look into these documents further.


    Just thought I should give you a better explanation of the data model (if it helps). This is how it was explained to me:

    - A Contact can have several memberships (therefore we do a loop through them). 
    - A Membership is of a certain main_membership (like the type of the membership). this is where the bool is_main_membership is that we want to check against (one of the if statements).
    - A Membership also has a reason for cancelation which is the 'reason' entity. We don't want any memberships with the reason of 'Deceased' for example which is one of the codes (we use codes because they are identical through all of our environments, but could use the unique identifier as well if that is easier).


    6735.Untitled-Diagram-_2800_1_2900_.png

    Does this help anything? Or if there is any other info you need that can help you out, please don't hesitate to ask!

    EDIT:
    As written in you first link, this should work. So, I basically just need to find the correct entity reference names to make it work.

    EDIT 2:
    And how does the assist edit create or where does it get the relationships name? It is not the relationship names viewed on the tables in the solution. Or how is it built so that we can copy that syntax?

    Best regards,
    Matilda

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: Retrive a field on a lookup from a loop item (this.lookup.field)

    Hi Matilda,

    Since the entity you’re using is a custom one, the naming of the fields, the relationship to Contact, etc. are not clear.

    Please refer to the following sections to know more about the expressions:

    Expressions created by assist edit

    Conditional statements and comparisons

     

    And here is a tutorial about how to use code block and dynamic content with an N:1 (Contact: the other entity) relationship in marketing emails.

    (+) Marketing Emails with custom code/Dynamics content - Marketing Community

     

    You can adjust your code according to the above docs, or provide more info to me. For example, how the relationship between this entity and Contact is defined.

     

    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

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,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans