0

Can we use lookuprows() function of AMPScript like this?

LookupRows(@ContactDE,'id',@SubscriberKey)

I have seen this code in the one of the email but I am not getting it instead of DE name why they have used @ContactDE? Is there any significance importance of using with "@" ?

Please help me to understand this.

Thanks Adam

1 Answer 1

0

Yes, you can use an AMPscript variable as the Data Extension name.

Perhaps the email is coded to work in multiple business units when using the Multi-Org Connector, where the sync'd Contact DE name varies -- like Contact_Salesforce and Contact_Salesforce_1 respectively.

%%[

Set @ContactDE = "B1kUrHHh"
set @SubscriberKey = "098765432109876543"
set @rows = lookupRows(@ContactDE, "id", @SubscriberKey)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

  for @i = 1 to @rowCount do

    set @row = row(@rows, @i)
    set @firstName = field(@row,"firstName")

    ]%%

    <br>Row %%=v(@i)=%%, firstName: %%=v(@firstName)=%%

    %%[

  next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%

Output

Row 1, firstName: Jane
Row 2, firstName: Sam
Row 3, firstName: Emma

Try it yourself: https://mcsnippets.herokuapp.com/s/B1kUrHHh

1
  • Thank you so much!
    – Adam Coder
    Commented Nov 17, 2023 at 12:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .