2

I’m stuck trying to create an email with SSJS. I have the email being created in the account, but the required personalization strings (e.g. %%profile_center%%) in the HTMLBody and TextBody values are being evaluated during creation. So when I go into the account after the SSJS processes, I see the actual profile center URL, when I want to see the variable with percent signs still. Have you run into this?

Here is my code:

var HTMLBody = "";
HTMLBody += '<b>This is a test email</b>';
HTMLBody += '<a href="%%profile_center_url%%" alias="Update Profile">Update Profile</a>';
HTMLBody += 'This email was sent by: %%Member_Busname%%';
HTMLBody += '%%Member_Addr%%, %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%';

var TextBody = HTMLBody.replace(/(<([^>]+)>)/ig, "");

var EmailConfig = {
                CustomerKey:"Email",
                Name:"Email",
                Subject:"Some Email",
                HTMLBody:HTMLBody,
                TextBody:TextBody,
                IsActive:"true",
                IsHTMLPaste:"true",
                Status:"active",    
                EmailType:"HTML",
                CharacterSet:"US-ASCII",
                HasDynamicSubjectLine:"false"
};
var NewEmail = Email.Add(EmailConfig);     
  • Where are you seeing the evaluated AMPScript? It shouldn't evaluate unless you're doing a Send or Send Preview. – Adam Spriggs May 5 '15 at 20:07
1

If you're running this on a landing page, then I'd try concatenating the double percents separately.

var HTMLBody = "";
HTMLBody += '<b>This is a test email</b>';
HTMLBody += '<a href="' + '%%' + 'profile_center_url' + '%%' + '" alias="Update Profile">Update Profile</a>';
HTMLBody += 'This email was sent by: ' + '%%' + 'Member_Busname' + '%%';
HTMLBody += '%%' + 'Member_Addr' + '%%' + ', ' + '%%' + 'Member_City' + '%%' + ', ';
HTMLBody += '%%' + 'Member_State' + '%%' + ', ' + '%%' + 'Member_PostalCode' + '%%' + ', ' + '%%' + 'Member_Country' + '%%';

var TextBody = HTMLBody.replace(/(<([^>]+)>)/ig, "");

var EmailConfig = {
                CustomerKey:"Email",
                Name:"Email",
                Subject:"Some Email",
                HTMLBody:HTMLBody,
                TextBody:TextBody,
                IsActive:"true",
                IsHTMLPaste:"true",
                Status:"active",    
                EmailType:"HTML",
                CharacterSet:"US-ASCII",
                HasDynamicSubjectLine:"false"
};
var NewEmail = Email.Add(EmailConfig); 
| improve this answer | |
  • Adam, great job solving this. I didn't even see the landing page being the issue. I tested this and it works like a charm! Thank you. – Michael May 6 '15 at 13:41

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.