You need to sign in to do that
Don't have an account?
Unexpected Javascript in emailTemplate (any takers?)
Visualforce is adding some Javascript to my email templates that gets displayed in the Activity History and also in at least one email client out on the 'net. The content of the script doesn't even look like it is essential to the template.
First, the code as it appears in my .email file:
<apex:repeat var="cx" value="{!relatedTo.OpportunityLineItems}">
<tr>
<td>{!cx.PricebookEntry.product2.description}</td>
<td><div align="right"><apex:outputField value="{!cx.UnitPrice}"/></div></td>
<td><div align="right"><apex:outputField value="{!cx.Quantity}"/></div></td>
<td> </td>
</tr>
</apex:repeat>
Pretty straightforward usage, just building a dynamic table of Opportunity Products.
The HTML and Javascript that appears for that exact same portion, when repeated twice for two records, is:
<tr>
<td>mCLASS®:DIBELS® Software Annual Student Subscription</td>
<td><div align="right"><script type="text/javascript"> if(!window.sfdcPage){window.sfdcPage = new ApexPage();}
UserContext.initialize({'locale':'en_US','timeFormat':'h:mm a','today':'5\/19\/2009 6:09 PM','userPreferences':[{'value':true,'index':112,'name':'HideInlineEditSplash'}
,{'value':true,'index':114,'name':'OverrideTaskSendNotification'}
,{'value':false,'index':115,'name':'DefaultTaskSendNotification'}
,{'value':false,'index':119,'name':'HideUserLayoutStdFieldInfo'}
,{'value':false,'index':116,'name':'HideRPPWarning'}
,{'value':false,'index':87,'name':'HideInlineSchedulingSplash'}
,{'value':false,'index':88,'name':'HideCRUCNotification'}
,{'value':true,'index':89,'name':'HideNewPLESplash'}
,{'value':false,'index':90,'name':'HideNewPLEWarnIE6'}
,{'value':false,'index':122,'name':'HideOverrideSharingMessage'}
],'startOfWeek':'1','isAccessibleMode':false,'ampm':['AM','PM'],'userId':'00530000000pvUP','dateTimeFormat':'M\/d\/yyyy h:mm a','dateFormat':'M\/d\/yyyy','language':'en_US','siteUrlPrefix':''}
);
</script><span id="j_id0:emailTemplate:j_id3:j_id4:j_id16:0:j_id20">$6.00</span></div></td>
<td><div align="right"><span id="j_id0:emailTemplate:j_id3:j_id4:j_id16:0:j_id22">100.00</span></div></td>
<td> </td>
</tr>
<tr>
<td>mCLASS® Platform Annual Student Subscription</td>
<td><div align="right"><span id="j_id0:emailTemplate:j_id3:j_id4:j_id16:1:j_id20">$8.00</span></div></td>
<td><div align="right"><span id="j_id0:emailTemplate:j_id3:j_id4:j_id16:1:j_id22">100.00</span></div></td>
<td> </td>
</tr>
I know that Visualforce processes the code and converts it to HTML, but I just cannot figure out what purpose this <script> has:
<script type="text/javascript"> if(!window.sfdcPage){window.sfdcPage = new ApexPage();}
UserContext.initialize({'locale':'en_US','timeFormat':'h:mm a','today':'5\/19\/2009 6:09 PM','userPreferences':[{'value':true,'index':112,'name':'HideInlineEditSplash'}
,{'value':true,'index':114,'name':'OverrideTaskSendNotification'}
,{'value':false,'index':115,'name':'DefaultTaskSendNotification'}
,{'value':false,'index':119,'name':'HideUserLayoutStdFieldInfo'}
,{'value':false,'index':116,'name':'HideRPPWarning'}
,{'value':false,'index':87,'name':'HideInlineSchedulingSplash'}
,{'value':false,'index':88,'name':'HideCRUCNotification'}
,{'value':true,'index':89,'name':'HideNewPLESplash'}
,{'value':false,'index':90,'name':'HideNewPLEWarnIE6'}
,{'value':false,'index':122,'name':'HideOverrideSharingMessage'}
],'startOfWeek':'1','isAccessibleMode':false,'ampm':['AM','PM'],'userId':'00530000000pvUP','dateTimeFormat':'M\/d\/yyyy h:mm a','dateFormat':'M\/d\/yyyy','language':'en_US','siteUrlPrefix':''}
);
</script>
Anyone else seen this in their Visualforce templates? Is it normal and I just have to accept that crappier email clients can't deal with JS in the <body>? I find it suspicious that it shows up in Task rendition of the Activity History.
Thanks for shedding any light you can,
Luke C
I figure out which fields in our Visualforce email template were causing the script to appear. The apex:outputField component is causing the script to appear. The final HTML looks fine when you use the apex:outputText component instead, however you lose any formatting on fields like dates and have to then style the date field to your liking.
All Answers
I'm having the same issue too. Did you get it resolved? Any body who can help please?
Thanks
I'm creating a VF email template with a table of Cases. I'm getting the same javascript displaying in my HTML emails in Outlook 2002. I don't have another email client to check with.
SF should at least be giving us an option to switch off this script injection in emails!! It looks fine in preview mode but that is displayed through a regular web browser.
The same thing is happening to me. It shows up if you click on View Original in Gmail and also gives a warning about a script in Outlook. Some webmail clients won't even render the e-mail because it contains that script.
The e-mail itself is rendering fine, but this funny script that is totally unrelated to our template will definitely land the e-mail in some Spam folders.
Please let me know if anyone has gotten any sort of explanation as to why this may be happening.
I figure out which fields in our Visualforce email template were causing the script to appear. The apex:outputField component is causing the script to appear. The final HTML looks fine when you use the apex:outputText component instead, however you lose any formatting on fields like dates and have to then style the date field to your liking.
I also have this issue when trying to display currencies in email templates. I've had to use custom components with custom controllers to get the converted currency to display. I created this idea to see if maybe an attribute can be added to the component to leave out the javascript or to leave it out when used in email templates. Please promote.