0

I have 2 pieces of text content I would like to make 'Dynamic' in Salesforce Marketing cloud content builder.

1) CUSTID: I currently have a data extension column called 'CUSTID', and in the email I have basic AMPscript which is ID:%%CUSTID%%, which obviously shows the %%CUSTID%% directly from the data extension. But in cases where 'CUSTID' is NULL, how can I completely hide the 'ID:%%CUSTID%%' text in the email? At the moment it shows up with ID:______ (blank)

2) I would like to add a dynamic office address. That is, if the data extension has a column called 'City' which says the customer is located in City A, I would like to pull the local City A office address (from a second 'lookup' data extension) into the email. On the other hand, if the 'City' value is NULL in the data extension, just hide the entire line: just like the CUSTID above

I'm new AMPscript and so would love any assistance here! Thank you in advance!

0

For number 1:

%%[
  SET @CUSTID = AttributeValue('CUSTID')
  IF NOT EMPTY(@CUSTID) THEN
]%%
  ID: %%=v(@CUSTID)=%%
%%[ ENDIF ]%%

you would wrap the whole thing in an IF statement to have it only displayed if CUSTID is not empty. I utilized AttributeValue as it allows for better error handling as well.

For number 2:

%%[
  SET @City = AttributeValue('City')
  SET @LookupDE = 'myLookupDE'

  IF NOT EMPTY(@City) THEN

    SET @officeAddr = LOOKUP(@LookupDE,"OfficeAddress","City",@City)
]%%
  Address: %%=v(@officeAddr)=%%
%%[ endif ]%%

In this one, we use the IF statement again, checking for a value in City. We also utilize AttributeValue again. The new part is the LOOKUP() statement, which will look at the defined 'LookupDE' and grab the field 'OfficeAddress' from the record where 'City' is equal to the city defined inside the sendable data. Adjust the field names and DE names as necessary to make it fit your needs.

1
  • 1
    Amazing thank you so much, going to try this out and come back to confirm! Jun 13 '20 at 11:57

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.