Forum Discussion

MeaganN's avatar
MeaganN
Qrew Member
3 years ago

Button with Mailto link - Code stops working if & is in a field

Hello, 

I have a button that generates an email with fields from a specific record.  If a field contains any contents with an &, anything below the & will not populate in the email. How can I ensure the Mailto Link allows & characters?

Example: 
"mailto:"&""&[Email 1]&
"\n"&"?subject="&"\n"&[Record]&""&
"&body="&"Location Name: "& [Location Name] 
"%0D"
&"field2"&
"%0D"
&"field3"&
""

 --- If Location Name for the records is AT&T, then the body of the email will be "AT" and nothing after... --- 

How can I ensure the mailto link copies the exact field contents without stopping at the & character? 

Thanks!

------------------------------
Meagan
------------------------------

3 Replies

  • '&' is a special character in the coding which needs to be 'escaped' or otherwise excluded.  One approach is to use ATT instead of AT&T when this happens:

    "mailto:"&""&[Email 1]&
    "\n"&"?subject="&"\n"&[Record]&""&
    "&body="&"Location Name: "& (If([Location Name]="AT&T","ATT",[Location Name]))
    "%0D"
    &"field2"&
    "%0D"
    &"field3"&
    ""

    This might work also and retain the '&' correctly in AT&T:

    "mailto:"&""&[Email 1]&
    "\n"&"?subject="&"\n"&[Record]&""&
    "&body="&"Location Name: "& (If([Location Name]="AT&T","AT&T",[Location Name]))
    "%0D"
    &"field2"&
    "%0D"
    &"field3"&
    ""

    ------------------------------
    Jeff Peterson
    ------------------------------

  • Use URL Encode. These are my notes. I am not totally sure if it works with the Ampersand.

    var text Subject = 
        "Enter Subject Line Text here " & [Add Fields If Desired] ;
     
    var text File = URLRoot() & "up/" & Dbid() & "/a/r" & [Record ID#] & "/e57/v0"; //use this if you want to include a file link

    var text Body = 
         URLEncode("Enter text for body here")
        & "%0A%0A"                                                                                       //THIS IS A LINE BREAK PLUS SKIPS A LINE
        & URLEncode("Company Name: " & [Company Name]) // EXAMPLE OF HOW TO ENTER TEXT AND A FIELD
        & "%0D%0A"                                                                                      //THIS IS A LINE BREAK, DOES NOT SKIP A LINE
        & URLEncode("File Link: " & $File)
        & "%0A%0A"
        & URLEncode("QuickBase Link: " & [Field]));

    var text Email = "mailto:ThisName@fakeemail.com" //WHAT EMAILS ARE IN THE TO LINE
    & "?cc=ThisName@fakeemail.com"                                 //WHAT EMAILS ARE IN THE CC LINE
    & "&subject=" & URLEncode($Subject)                             //NOTE: If you remove the cc line, then: & "?subject=" & URLEncode($Subject)       
    & "&body=" & $Body;                                                                      // The first line after mail to should have a '?' and NO "&". This indicates everything following is being set.

      
    "<a href="
     & $Email
     & ">" & "Create Email" & "</a>"

    ------------------------------
    Mike Tamoush
    ------------------------------
    • MeaganN's avatar
      MeaganN
      Qrew Member
      URLEncode worked perfectly! Thanks for the help.

      ------------------------------
      Meagan Kellagher
      ------------------------------