0

I have 3 data extensions and in 2 of them the syntax of First Name is the same and in the third the syntax is different. I am trying to write a script to pull the First name. The amp script is working; the only issue I am facing is when the same email address with the same key is in 2 data extensions; although its deduped at the time of the send the first name appears twice. I can't figure what exactly is missing in the if logic to prevent this. I know I can use a query activity to format the name for the third DE to match the other 2 and use the %%%% for pulling the first name but I need to understand why my current script isnt working.

Any idea is appreciated! thanks, G

%%[ 

var @rows2,@row2,@rowCount2
Var @lookupValue2
SET @lookupValue2=AttributeValue('Contact ID')
SET @rows2=LookupRows('FirstNamesDEs','Contact ID',@lookupValue2)
SET @rowCount2=rowcount(@rows2)

If @rowCount2>0 then 
    Var @first2
    SET @row2=row(@rows2,1)
    SET @first2=field(@row2,'First Name')
]%%
%%[else]%%
%%[endif]%%

%%[ 

var @rows3,@row3,@rowCount3
Var @lookupValue3
SET @lookupValue3=AttributeValue('Contact ID')
SET @rows3=LookupRows('FirstNamesDe2','Contact ID',@lookupValue3)
SET @rowCount3=rowcount(@rows3)

If @rowCount3>0 then 
    Var @first3
    SET @row3=row(@rows3,1)
    SET @first3=field(@row3,'First_Name')
]%%
%%[else]%% 
%%[endif]%%

%%[ 
var @rows4,@row4,@rowCount4 
Var @lookupValue4
SET @lookupValue4=AttributeValue('Contact ID')
SET @rows4=LookupRows('FirstNames_Exclusions','Contact ID',@lookupValue4)

SET @rowCount4=rowcount(@rows4)

If @rowCount4>0 then 
    Var @first4
    SET @row4=row(@rows4,1)
    SET @first4=field(@row4,'First_Name')
]%%
%%[else]%%
%%[endif]%%

%%[if @first2==@first3==@first4 then]%%
    %%=v(@first2)=%%
%%[endif]%%
%%[else]%%

%%[if @first2==@first3 then]%%
    %%=v(@first2)=%%
%%[else]%%
%%[endif]%%

%%[if @first2==@first4 then]%%
    %%=v(@first2)=%%
%%[else]%%
%%[endif]%%

%%[if @first3==@first4 then]%%
    %%=v(@first3)=%%
%%[else]%%
%%[endif]%%

%%[if not empty (@first2) OR not empty (@first3) or not empty (@first4) then]%%
    %%=v(@first2)=%%%%=v(@first3)=%%%%=v(@first4)=%%
%%[else]%%

    %%[
    var @text 
    set @text="Dear Traveler" 
    Output(v(@text))
    ]%%

%%[endif]%%
  • sorry for the terrible formatting. In my notepad the format showed the code correctly formatted – Giulietta Jan 26 '18 at 10:19
0

I think you can accomplish what you're wanting in a much simpler way -- by utilizing the Lookup() and empty() functions:

%%[

var @contactID, @first2, @first3, @first4, @firstName
set @contactID = AttributeValue('Contact ID')
var @first2 = Lookup("FirstNamesDEs", "First Name", "Contact ID", @contactID)
var @first3 = Lookup("FirstNamesDe2", "First_Name", "Contact ID", @contactID)
var @first4 = Lookup("FirstNames_Exclusions", "First_Name", "Contact ID", @contactID)

/* for debugging */
output(concat("<br>contactID: ", @contactID))
output(concat("<br>first2: ", @first2))
output(concat("<br>first3: ", @first3))
output(concat("<br>first4: ", @first4))

if not empty(@first2) then

  set @firstName = @first2

elseif not empty(@first3) then

  set @firstName = @first3

elseif not empty(@first4) then

  set @firstName = @first4

else

 set @firstName = "Traveler"

endif

output(concat("<br>Dear ", properCase(@firstName), ","))

]%%
  • Thanks Adam! I am very new to amp script. Very elegant solution. Didn't know I can just declare the AttributeValue one time if the syntax for this field is the same in my data extensions. Makes total sense and it achieves what I need. – Giulietta Jan 29 '18 at 8:23

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.