Expand my Community achievements bar.

SOLVED

Trying to get related values from a table where it may relate to zero or many?

Avatar

Level 1

I've got a relation in my profile to a Work Order table, and that Work order table may have for example be like this

 

Profile Email | Profile Work Order ID

john@doe.com | 1234

 

Then I have the Work Order Table like so

WO - ID | Product Name

1234 | Thing 1

1234 | Thing 2

1234 | Thing 3

 

So in my email I want to say something like "Hey John, thanks for buying Thing 1, Thing 2, Thing 3.  We appreciate your business!"

 

Right now I'm trying to go through an Enrichment where I set @productName to that value.  Then I add in that to my code using:

<% var productName = ''; var product = context.targetData.productName; if (productName !== '') { productName = product;} document.write(productName); %>

 

This doesn't seem to be working.  Is it returning an array that I need to break out? Should I be doing it a different way using the WYSWYG tool, and if so where do I look for that?  Any help would be great.  This is driving me insane.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

To get that working, you would need to:

  • Define an enrichment
  • inside the enrichment add the target schema and choose type = collection.
    Note: here you need to define a max number of items to fetch, unfortunately you can't easily loop over an unlimited set
  • then add the required fields as target data in that enrichment part
  • Then in the email you can access it via order_1.item, order_2.item
    i.e. not a loop over an array but each collection item is named with an index
    So you also always need to check whether the record also contains a value before rendering it

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

To get that working, you would need to:

  • Define an enrichment
  • inside the enrichment add the target schema and choose type = collection.
    Note: here you need to define a max number of items to fetch, unfortunately you can't easily loop over an unlimited set
  • then add the required fields as target data in that enrichment part
  • Then in the email you can access it via order_1.item, order_2.item
    i.e. not a loop over an array but each collection item is named with an index
    So you also always need to check whether the record also contains a value before rendering it