I have a custom button (JavaScript) which copies the Description field from Event to my custom Object like this:

summary.Discussion_Topics__c = '{!Event.Description}';

Both fields are of Long Text Area(32000) type. The button works fine when the Description has one line. When it includes multiple lines the javascript throws an exception. I would like to retain the formatting and copy the Description with multiple line. Can that be achieved? How?


The JSENCODE Visualforce function will escape the line feeds and other unsafe characters:

summary.Discussion_Topics__c = '{!JSENCODE(Event.Description)}';

This works in custom button JavaScript too e.g. in a custom "Execute JavaScript" button on Account:

var d = '{!JSENCODE(Account.Description)}';
  • Does JSENCODE available for a custom button JS? – Dedo Nov 2 '14 at 17:01
  • @Dedo Yes - see the example I added to the answer. – Keith C Nov 2 '14 at 17:15

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.