[SalesForce] AMPscript CONCAT using a variable

I am working on a script that will display content based on subscriber's local value from Sales Cloud. Everything works fine until the Concat function, where I am trying to include a variable, but it seems to be treated as a string. I tried with and without '', but the result is the same – I am getting the following error:

An error occurred when attempting to evaluate a ContentBlockByName
function call. Function Call: ContentBlockbyName("@content") See
inner exception for details. Invalid length parameter passed to the
LEFT or SUBSTRING function.

My Concat function renders like this:

Content Builder\@local\@local 
Content Builder\@local\@local_footer 
Content Builder\@local\@local_subject

Can you please let me know how to correctly include the variable?

%%[ var @skey, @rs, @rowCount, @row, @local, @content, @footer, @subject

Set @skey = [CampaignMember:Common:Id]
Set @rs= RetrieveSalesforceObjects('Contact', 'Local__c', 'Id', '=', @skey)
set @rowCount = rowcount(@rs)

IF @rowCount > 0 then
set @row = row(@rs,1)
set @local = field(@row,"Local__c")

ELSE
set @local = "en_US"
ENDIF

set @content = Concat('Content Builder\','@local','\', '@local')

set @footer = Concat('Content Builder\','@local','\', '@local', '_','footer')

set @subject = Concat('Content Builder\','@local','\', '@local', '_','subject')

]%%  

%%=ContentBlockbyName("@content")=%%
%%=ContentBlockbyName("@footer")=%%
%%=ContentBlockbyName("@subject")=%%

Best Answer

You just should not insert ' before you use variables, if you do that you will use the string and not the variable. You can use " or ' it makes no difference.

%%[ 
    var @skey, @rs, @rowCount, @row, @local, @content, @footer, @subject

    Set @skey = [CampaignMember:Common:Id]
    Set @rs= RetrieveSalesforceObjects('Contact', 'Local__c', 'Id', '=', @skey)
    set @rowCount = rowcount(@rs)

    IF @rowCount > 0 then
        set @row = row(@rs,1)
        set @local = field(@row,"Local__c")

    ELSE
        set @local = "en_US"
    ENDIF

    set @content = Concat("Content Builder\",@local,"\", @local)
    set @footer = Concat("Content Builder\",@local,"\", @local, "_footer")
    set @subject = Concat("Content Builder\",@local,"\", @local, "_subject")

]%%  

%%=ContentBlockbyName(@content)=%%
%%=ContentBlockbyName(@footer)=%%
%%=ContentBlockbyName(@subject)=%%

Here is an example:

%%[
@var = "Salesforce"
Concat(@var, "bla", 'bla') 
/*works. Result is: Salesforceblabla*/
Concat('@var', 'bla', 'bla') 
/*works. Result is: @varblabla*/
]%%
Related Topic