1

I have two data extensions.

Entry Data extension

| CONTACT_ID |
+------------+
|          1 |
|          2 |
|          3 |
+------------+

Lookup data extension

+------------+-----------+
| CONTACT_ID | PRICEPLAN |
+------------+-----------+
|          1 | a         |
|          1 | b         |
|          2 | b         |
|          3 | c         |
+------------+-----------+

I want to be able to look up on the CONTACT_ID and show PRICEPLAN value in the email.
So in the email i would like the output to be:

For CONTACT_ID = 1 show priceplan a and b

Here is my code which only shows me priceplan a.

%%[

SET @CONTACT_ID = CONTACT_ID
set @rows = LookupRows("LOOKUP_DATA_EXTENSION", "CONTACT_ID", @CONTACT_ID)


IF RowCount(@rows) > 0 Then

    FOR @i = 1 To RowCount(@rows) Do
    SET @row = Row(@rows,@i)
    SET @priceplan_name = Field(@row,"PRICEPLAN")

    next @i

    ENDIF

    ]%%

Your Priceplan: %%=v(@priceplan_name)=%%

CURRENT OUTPUT:
Your Priceplan: a

WANTED OUTPUT FOR CONTACT_ID = 1
Your Priceplan: a, b

I managed to fix it myself. Here is the code that worked.

%%[

SET @CONTACT_ID = CONTACT_ID
set @rows = LookupRows("LOOKUP_DATA_EXTENSION", "CONTACT_ID", @CONTACT_ID)


IF RowCount(@rows) > 0 Then

    FOR @i = 1 To RowCount(@rows) Do
    SET @row = Row(@rows,@i)
    SET @priceplan_name = Field(@row,"PRICEPLAN")

 ]%% 
Your Priceplan: %%=v(@priceplan_name)=%%<br>

%%[

    next @i

    ENDIF

    ]%%

  • 2
    Lookup function will only lookup a single value, you cannot loop it. You need to use LookupRows, as in the second code sample you provided and loop it do display all values found from 1 to rowcount - take a look here: developer.salesforce.com/docs/… – zuzannamj Aug 2 '19 at 17:29
  • Oh great! Thank you for the information and the link! I will give it a try – Martin Ho Aug 2 '19 at 17:48
  • And you don’t need to define @lookupValue twice - any of the two will work if it’s a column in your sendable DE – zuzannamj Aug 2 '19 at 17:57
  • It is. I am learning new things here. Thanks! – Martin Ho Aug 2 '19 at 17:59
  • @CodeRage I have made a new code. There is no output. Can you see what I am doing wrong? – Martin Ho Aug 2 '19 at 20:49
1

Try this:

%%[
SET @CONTACT_ID = CONTACT_ID
set @rows = LookupRows("LOOKUP_DATA_EXTENSION", "CONTACT_ID", @

FOR @i = 1 To RowCount(@rows) DO
SET @row = Row(@rows,@i)
SET @priceplan_name = Field(@row,"PRICEPLAN")
]%%

Your Priceplan: %%=v(@priceplan_name)=%%<br>

%%[ next @i ]%%
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.