Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Ampersand (&) in a field value is disrupting my e-mail script

Geckoz100
Level 5
Level 5

I have a lengthy e-mail script in which one of the fields sometimes contains an ampersand as a value, e.g., "Litigation & Enforcement".  The value is set in a drop-down earlier in the form.  When the field has a value like that, it cancels everything that comes after that point in the e-mail script, because it interprets it as a "&" which is used to build the body of the script.  Is there are any way to have it ignore the ampersand in the field value or do I have to change my values in the drop-down?  Thanks for any help.

1 Accepted Solution
Geckoz100
Correct answer by
Level 5
Level 5

Hey genel89623801, that did the trick!  I had definitely not gotten past the issue and had resigned myself to replacing the ampersand with "and".

Using the encodeURIComponent function wouldn't work for me within the body of the e-mail script, though I tried using value, rawValue and full XFA path notation with it. But it did work when I replaced the ampersand in a variable first, outside of the e-mail script, as below.  I consider resolving this minor annoyance a great success. Thanks for the help.

var str = DeptName.rawValue;

var Department = str.replace(/\&/, encodeURIComponent("%26"));

SubmitReal.event__click.submit.target = "mailto:john@domain.com" +

"?cc=" + SupervisorEmail.rawValue +

"&subject=Accepting speaker sequest on " + Page1.EventDetails.Group2.SpeakingDate.rawValue +

"&body=RE:Request for a Speaker\n" +

"I will be attending on behalf of " + Department + ".\n\n" +

"Thank you,\n" +

SenderName.rawValue;

SubmitReal.execEvent("click");

View solution in original post

8 Replies
_Bruce_Robertson
Level 10
Level 10

Hi,

Not sure how you are building up your email script but somehow you need to replace the "&" character with the escaped value of "%26". 

Regards

Bruce

Geckoz100
Level 5
Level 5

Hello Bruce,

Thanks for your reply.  I tried using that escaped value and it didn't work.  I'm using a the script below in a dummy button which "clicks" a hidden submit button.  So the script picks up a value of the name of one of the departments, which can have an ampersand, like "Advisory Board & Councils".  So when the script runs I don't get an error (even with the debugger), it just chops everything that comes after that point in the script.  When I click the Submit button that has the script below, everything after my form variable "Department" would just disappear.


var Department = str.replace(/\&/, "%26");



SubmitReal.event__click.submit.target = "mailto:john@domain.com" +


"?cc=" + SupervisorEmail.rawValue +


"&subject=Accepting speaker sequest on " + Page1.EventDetails.Group2.SpeakingDate.rawValue +


"&body=RE:Request for a Speaker\n" +


"I will be attending on behalf of " + Department + ".\n\n" +


"Thank you,\n" +


SpeakerName.rawValue;


SubmitReal.execEvent("click");


Thanks again for any help.

genel89623801
Level 1
Level 1

I think I may have a similar problem not too long ago. BR001_ACP may have the right idea... try encoding the subject line as I have below:

EmailTitle.rawValue + encodeURIComponent(TopSection.FormName.rawValue) + "&body=" +

reference: http://stackoverflow.com/questions/11294107/how-can-i-send-the-ampersand-character-via-ajax

Geckoz100
Level 5
Level 5

Thanks for the responses.  Sorry genel89623801, but I don't understand the suggestion.  Where my script is having trouble is in the body of the e-mail where the "Department" field is (line 7).  Some department names have an ampersand in them (e.g., Litigation & Enforcement), so the script just breaks right at that point.

_Bruce_Robertson
Level 10
Level 10

Hi,

Seems the %26 only works in a mailto hyperlink and the Doc.mailForm/mailDoc methods.  The problem is the "&" character is used as a delimiter in the mailto protocol.  Seems the submit email button is expecting one of the key words, (that is to, cc, bcc, body or subject) , doesn't find it so gives up.

Maybe someone else know how to escape the "&" but might be quicker to change the values in the drop down.

Regards

Bruce

Geckoz100
Level 5
Level 5

Yes, I eventually had to do that.  Before the e-mail is generated I just take the value of the department and convert any ampersands to the word "and".  They bosses want to keep the "&" in the names in the drop-downs since that's how they're officially written.  Thanks again for the replies.

genel89623801
Level 1
Level 1

Hi Geckoz100​,

I hope you've gotten passed this, if not may I suggest replacing department in line 7 with encodeURIComponent(Department)

and if that doesn't work, you may have to try alternatively replacing with encodeURIComponent(Department.value)

Geckoz100
Correct answer by
Level 5
Level 5

Hey genel89623801, that did the trick!  I had definitely not gotten past the issue and had resigned myself to replacing the ampersand with "and".

Using the encodeURIComponent function wouldn't work for me within the body of the e-mail script, though I tried using value, rawValue and full XFA path notation with it. But it did work when I replaced the ampersand in a variable first, outside of the e-mail script, as below.  I consider resolving this minor annoyance a great success. Thanks for the help.

var str = DeptName.rawValue;

var Department = str.replace(/\&/, encodeURIComponent("%26"));

SubmitReal.event__click.submit.target = "mailto:john@domain.com" +

"?cc=" + SupervisorEmail.rawValue +

"&subject=Accepting speaker sequest on " + Page1.EventDetails.Group2.SpeakingDate.rawValue +

"&body=RE:Request for a Speaker\n" +

"I will be attending on behalf of " + Department + ".\n\n" +

"Thank you,\n" +

SenderName.rawValue;

SubmitReal.execEvent("click");

View solution in original post