2

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")=%%
1

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*/
]%%
  • Thanks, it worked. I also had to get rid of quotes in the ContentBlockbyName function: %%=ContentBlockbyName(@content)=%% %%=ContentBlockbyName(@footer)=%% %%=ContentBlockbyName(@subject)=%% – zuzannamj Feb 15 at 9:49
  • Oh yeah. I overlooked these. I adapted the answer. – Johannes Schapdick Feb 15 at 9:51

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.