0

I've attempted to use the following AMPscript to show nothing if a field contains no value. It is erroring, no doubt because there is an obvious syntax error somewhere, but I cannot see where.
Any help would be appreciated.

%%=iif(empty(@Variable_Scholarship_Name__c),"",Scholarship Title:%%Variable_Scholarship_Name__c%% 

Scholarship Amount: $%%=FormatNumber(AttributeValue("Variable_Scholarship_Amount__c"),"#,###")=%%
=%%

If the field is not empty, I need the email to display as follows:

Scholarship Title: Genius

Scholarship Amount: $20

Thank you in advance!

1 Answer 1

2

You first need to lookup those values from somewhere and judging by the __c, those come from Salesforce, so you either need to point from which object in Salesforce or which Synchronized DE they should come from.

Using the iif function for this use case would be too complicated, so it's better to use an AMPscript block wit an if/else statement:

%%[
SET @rows = RetrieveSalesforceObjects(
"ObjectName",
"Variable_Scholarship_Name__c,Variable_Scholarship_Amount__c", 
"Id" = "SubscriberID")

SET @row = row(@rows,1)
SET @Variable_Scholarship_Name__c = field(@row,"Variable_Scholarship_Name__c")
SET @Variable_Scholarship_Amount__c = field(@row,"Variable_Scholarship_Amount__c")


IF NOT EMPTY(@Variable_Scholarship_Name__c) THEN
]%%

Scholarship Title: %%=v(@Variable_Scholarship_Name__c)=%%

Scholarship Amount: $%%=v(@Variable_Scholarship_Amount__c)=%%

%%[ENDIF]%%

Above will pull data directly from Salesforce, so only use it on CloudPages. You will need to replace "ObjectName" and "SubscriberID" in the above to point it to the right object and enable to identify the record correctly.

If you need this for an email, it's better to use Synchronized Data Extensions:

%%[
SET @rows = LookupRows("NameOfSynchedDE","Id", "Id")

SET @row = row(@rows,1)
SET @Variable_Scholarship_Name__c = field(@row,"Variable_Scholarship_Name__c")
SET @Variable_Scholarship_Amount__c = field(@row,"Variable_Scholarship_Amount__c")


IF NOT EMPTY(@Variable_Scholarship_Name__c) THEN
]%%

Scholarship Title: %%=v(@Variable_Scholarship_Name__c)=%%

Scholarship Amount: $%%=v(@Variable_Scholarship_Amount__c)=%%

%%[ENDIF]%%

Here you will need to replace "NameOfSynchedDE" with the name of your Data Extension, first "Id" with the Id column in that DE and the second "Id" with the Id to identify the correct record.

So, if for example, this data comes from the Contact_Salesforce synchronized data extension, the final code would look something like this:

%%[
SET @rows = LookupRows("Contact_Salesforce","Id", _subscriberkey)

SET @row = row(@rows,1)
SET @Variable_Scholarship_Name__c = field(@row,"Variable_Scholarship_Name__c")
SET @Variable_Scholarship_Amount__c = field(@row,"Variable_Scholarship_Amount__c")


IF NOT EMPTY(@Variable_Scholarship_Name__c) THEN
]%%

Scholarship Title: %%=v(@Variable_Scholarship_Name__c)=%%

Scholarship Amount: $%%=v(@Variable_Scholarship_Amount__c)=%%

%%[ENDIF]%%
4

You must log in to answer this question.

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