function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Don PierceDon Pierce 

Concatenating text and textarea fails in javascript

I am trying to concatenate two fields and insert into a Note.
It works fine when I use text but fails when I try to use a textarea
InstrumentName__c is a text(255) field and IntrumentProblem_c is textarea(255)
The following works fine:

var repnew3 = new sforce.SObject('Note');
repnew3.ParentId = qr.records.Id;
repnew3.Title = '{!Case.Subject}';
// combine 
repnew3.Body = '{!Case.InstrumentName__c}';
result3 = sforce.connection.create([repnew3]);

 This will not work:

var repnew3 = new sforce.SObject('Note');
repnew3.ParentId = qr.records.Id;
repnew3.Title = '{!Case.Subject}';
// combine 
repnew3.Body = '{!Case.InstrumentProblem__c}';
result3 = sforce.connection.create([repnew3]);

Is there a conversion process require or does the Note.Body field not accept textarea?

Ultimately I want to concatenate the two as follows:
var repnew3 = new sforce.SObject('Note');
repnew3.ParentId = qr.records.Id;
repnew3.Title = '{!Case.Subject}';
// combine 
repnew3.Body = 'Problem: ' + '{!Case.InstrumentProblem__c}' + '  Name: ' + '{!Case.InstrumentName__c}';
result3 = sforce.connection.create([repnew3]);

This is being used as a button action on the Case layout.
Best Answer chosen by Don Pierce
Don PierceDon Pierce
I used URLENCODE and that resolved the problem but of course the result is the text was:
zxc 
sadf 
sdf

is now

zxc%0D%0Asadf%0D%0Asdf

So I just did a replace with \r and \n and that resolved the issue.
This is the code:
var teststr = '{!URLENCODE(Case.Instrument_Problem__c)}';
teststr = teststr.replace(/%0D/g, '\r');
teststr = teststr.replace(/%0A/g, '\n');

repnew3.Body = teststr;
result3 = sforce.connection.create([repnew3]);
if(result3[0].success == 'true'){
    alert('A new Note was created Successfully.');
  }


 

All Answers

Ram K 35Ram K 35
Hi Don Pierce,
In case related Note ,body doesnot allow Textarea if any html styles are added to it.Once try without giving html style.
if it useful make it as best answer

THanks ,
Ram.    
Don PierceDon Pierce
What I have found is that if the TextArea contains more than one line of text it fails.  Works fine with one line of text.  Also I am pulling this field from the database.  I am wondering if it has to do with new line char or maybe cr character.  In Javascript could I replace those chars with blanks?
Don PierceDon Pierce
I used URLENCODE and that resolved the problem but of course the result is the text was:
zxc 
sadf 
sdf

is now

zxc%0D%0Asadf%0D%0Asdf

So I just did a replace with \r and \n and that resolved the issue.
This is the code:
var teststr = '{!URLENCODE(Case.Instrument_Problem__c)}';
teststr = teststr.replace(/%0D/g, '\r');
teststr = teststr.replace(/%0A/g, '\n');

repnew3.Body = teststr;
result3 = sforce.connection.create([repnew3]);
if(result3[0].success == 'true'){
    alert('A new Note was created Successfully.');
  }


 
This was selected as the best answer