Trying to get related values from a table where it may relate to zero or many? | Community
Skip to main content
May 17, 2022
Solved

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

  • May 17, 2022
  • 1 reply
  • 745 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by bisswang

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

1 reply

bisswangAdobe EmployeeAccepted solution
Adobe Employee
May 18, 2022

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