Getting this error: 'A variable name is not a valid because contains illegal characters. Variable names must begin with the @ symbol followed by one or more letters, numbers, or underscores. Variable Name: <' When trying to run this AMPscript code - the '<' symbol is not in

%%[ var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i, @Pricebookname

set @lookupValue = AttributeValue("Name") 
set @numRowsToReturn = 0 
set @rows = LookupOrderedRows("SalesforceApplication_Website",@numRowsToReturn,"Pricebook_Name__c
 asc","Name", @lookupValue) ]%% 

%%[ set @rowCount = rowcount(@rows) 

if @rowCount > 0 then

for @i = 1 TO @rowCount do

set @row = row(@rows,@i) 
set @Pricebookname = field(@row, "Pricebook_Name__c")

IF (@Pricebookname == 'city Low') then 


elseif (@Pricebookname == '43in B') then 


elseif (@Pricebookname == 'B saver') then


elseif (@Pricebookname == 'Nat G User - 2022') then 


EndiF ]%% 

%%[ next @i ]%% 
%%[ else ]%% 
%%[ endif ]%%

Any help is much appreciated

  • Try removing inline syntax for all AttachFile() , as you are already using %%[ ]%% ... Example: instead of %%=AttachFile(Contentbuilder,445768)=%% just use AttachFile(Contentbuilder,445768) Jun 22 at 5:21
  • Thanks, i now get this error: "Invalid Function Call<br>The specified attribute or custom object field name was not found for this client" Any ideas? Jun 23 at 1:33

1 Answer 1


There are multiple issues here, but let's start with the core one - the illegal < characters in variable names. You probably wrote your code in the Content tab instead of the HTML Editor of your block and some HTML like <br>, &nbsp;<br> were added by the editor to break the lines of the content.

Check your code here: enter image description here

and there you will probably find the illegal characters with added HTML tags.

It's a good practice to write your code in the HTML editor or simply in the Code Snippet content blocks which won't add extra HTML.

Other than that, as Vishal Kumar C V mentioned in his comment, you are using inline Ampscript in a code block, so code like this %%=AttachFile(Contentbuilder,445765)=%% should be changed to AttachFile(Contentbuilder,445765).

You're actually opening and closing the script block needlessly here - since you don't output anything as visible HTML and just adding attachments, all of this could be stored in a single block like this:

%%[ var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i, @Pricebookname

set @lookupValue = AttributeValue("Name") 
set @numRowsToReturn = 0 
set @rows = LookupOrderedRows("SalesforceApplication_Website",@numRowsToReturn,"Pricebook_Name__c
 asc","Name", @lookupValue) 

set @rowCount = rowcount(@rows) 

IF @rowCount > 0 THEN

    FOR @i = 1 TO @rowCount DO

        set @row = row(@rows,@i) 
        set @Pricebookname = field(@row, "Pricebook_Name__c")

        IF (@Pricebookname == 'city Low') THEN 

        ELSEIF (@Pricebookname == '43in B') THEN 

        ELSEIF (@Pricebookname == 'B saver') THEN

        ELSEIF (@Pricebookname == 'Nat G User - 2022') THEN 

    NEXT @i
  • Thanks Rafal, I made these changes, however, when I try to preview im now met with this error: "Invalid Function Call<br>The specified attribute or custom object field name was not found for this client Jun 23 at 1:28
  • @investincrypto sounds like you still have <br> in your code. Open it in the HTML editor and search for the <br> elements again Jun 24 at 9:38

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.