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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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

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

    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

  • Matilda Olsson Profile Picture
    10 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 214 Super User 2026 Season 1

#2
CU11031447-0 Profile Picture

CU11031447-0 100

#3
NeerajPawar Profile Picture

NeerajPawar 76

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans