You need to sign in to do that
Don't have an account?

Error for a long text Field In javscript when trying to merge fields
Here is the code i am using.
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var c = new sforce.SObject("Lead");
c.id = "{!Lead.Id}";
c.Contact_Attempt__c = 'True';
var discription = prompt("Call Discription", "");
var notes = "{!Lead.Discussion_Notes__c}";
var note = notes + "\r" + "{!User.Alias}" + "--" + discription + "--" + "{!NOW()}" ;
c.Discussion_Notes__c = note;
result = sforce.connection.update([c]);
window.location.reload();
Discussion_notes__c is the long text area i am using.. Its working for 1st two times. After it creates two lines it gives me a error saying "A problem with the OnClick JavaScript for this button or link was encountered:unterminated string literal"
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var c = new sforce.SObject("Lead");
c.id = "{!Lead.Id}";
c.Contact_Attempt__c = 'True';
var discription = prompt("Call Discription", "");
var notes = "{!Lead.Discussion_Notes__c}";
var note = notes + "\r" + "{!User.Alias}" + "--" + discription + "--" + "{!NOW()}" ;
c.Discussion_Notes__c = note;
result = sforce.connection.update([c]);
window.location.reload();
Discussion_notes__c is the long text area i am using.. Its working for 1st two times. After it creates two lines it gives me a error saying "A problem with the OnClick JavaScript for this button or link was encountered:unterminated string literal"
Hello, Vishnu,
I believe you can fix your problem by using the JSINHTMLENCODE() function[1]. See the modified line below when instantiating notes in your code.
var notes = "{!JSINHTMLENCODE(Lead.Discussion_Notes__c)}";
The problem is that every time you add new notes, a line break is added to the text stored inside Lead.Discussion_Notes__c. When you bring this value back into JavaScript as-is, it ends up writing the line break to your JavaScript inside your string declaration, which is not allowed. Salesforce's JSINHTMLENCODE() function magically handles the line breaks so that they don't break your code and still allows the line breaks be retained when going back into the database.
All Answers
Hello, Vishnu,
I believe you can fix your problem by using the JSINHTMLENCODE() function[1]. See the modified line below when instantiating notes in your code.
var notes = "{!JSINHTMLENCODE(Lead.Discussion_Notes__c)}";
The problem is that every time you add new notes, a line break is added to the text stored inside Lead.Discussion_Notes__c. When you bring this value back into JavaScript as-is, it ends up writing the line break to your JavaScript inside your string declaration, which is not allowed. Salesforce's JSINHTMLENCODE() function magically handles the line breaks so that they don't break your code and still allows the line breaks be retained when going back into the database.
Sorry, I left the link out in my previous reply!
[1]: JSINHTMLENCODE() function (http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_functions.htm)