this is a beginner AmpScript question. I can't seem to even get past "Step One" in my attempt to learn AmpScript.
I am trying to follow the "AmpScript 101 tutorial" located here
I am trying to set a list of variables per the first example in the tutorial:
%%[
Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
Set @memid = MemberID
Set @fname = FirstName
Set @lname = LastName
Set @prefname = PrefName
Set @address = Address
Set @zip = Zip
Set @mempref = MemPref
Set @plat = Plat
]%%
And the following code works fine with only the variable "@memid" set:
%%[
Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
Set @memid = MemberID
]%%
Then, when I set the variable "@fname," the code also works fine.
%%[
Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
Set @memid = MemberID
Set @fname = FirstName
]%%
Then, again, when I set the variable "@lname" the code also works.
%%[
Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
Set @memid = MemberID
Set @fname = FirstName
Set @lname = LastName
]%%
But if I try to set any more than those three variables, my code completely breaks. Why is this happening? I've searched and searched for an answer, and I can't seem to figure out what's going on.
For example, this code will throw an error:
%%[
Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
Set @memid = MemberID
Set @fname = FirstName
Set @lname = LastName
Set @prefname = PreferredName
]%%
(The error is "The SET variable value expresion(sic) is invalid. See inner exception for detail.
Script: Set @prefName = PreferredName
Variable Name: @prefname
The SET variable value expresion is invalid. See inner exception for detail.
Script: Set @prefname = PreferredName
Variable Name: @prefname
Index: 4459
ListID: 452"
Or, when I try to set any other variable such as @address, @zip, @mempref, or @plat, I get a similar error.
Also, any other random variable that I attempt to set creates the same error. For example, this code:
%%[
Var @grapefruit
Set @grapefruit = CitrusFruit
]%%
The code above produces this error: "The SET variable value expresion(sic) is invalid. See inner exception for detail.
Script: Set @grapefruit = CitrusFruit
Variable Name: @grapefruit
Index: 4312
ListID: 452"
I can't seem to successfully set ANY variables at all apart from three specific ones: @memid, @fname, @lname
The fact that I am only able to set three specific variables makes no sense to me. But I can't seem to spot what my error is, or where I'm going wrong, and I can't figure out why code in a basic 101 tutorial would not work for me. This is probably a silly, stupid question with an obvious answer, but I am truly stuck and cannot find a way to get out of the gate with this.
Information about my development environment:
I am using the SalesForce Marketing Cloud's development environment. I'm working under Email > Content > Template-based email. I have tried writing this same code in a straight HTML email, and I am getting precisely the same errors regardless of whether I'm using straight-up HTML or a template, but am currently working with template-based email. To see if the code is working, I am clicking "Send Preview," selecting a test recipient, and then clicking on "Generate Preview" which then either generates a functioning preview of the e-mail (with variables @memid, @fname, or @lname) or an error message (with any other attempt to set any other variable)
Best Answer
I think what you are running into, is that your account is not yet fully built out.
The reasone why
MemberID
,FirstName
,LastName
all work, is that the account already has those set up as profile attributes, and are listed as personalization stringsNote: If you marked the new attribute as a required field, all subscriber imports now must include this field. You may want to include a default value so that records can be saved even if a value isn't provided.
You will then be able to access those properties in your AMPscript.