AnsweredAssumed Answered

How to create dependent tinymce textarea according to the selection of email template name?

Question asked by Sohan Tirpude on Feb 20, 2015
Hello Everyone,
    I am using SugarCRM 6.5.x CE version. I want to make a dependent functionality where I have a dropdown field with list of email template name. And according to the selection of email template, textarea should be filled with email template body text. So, I have achieved the result.
    Now, instead of normal textarea, I want to show this body text in tinymce editor textarea. Now, I have "convert" my textarea into tinymce editor textarea by going through this url http://forums.sugarcrm.com/f3/fatal-smarty-error-when-adding-tinymce-33192/
    Now, when I chose email template from dropdown field, this tinymce textarea doesn't fill up with respective body text.
    This is my javascript for normal textarea, and its working
    
        function display_text(){
  if(typeof(document.getElementsByName('email_template_c')[0].value) != "undefined"){
   var custom_data = document.getElementsByName('email_template_c')[0].value;
   if(custom_data != ''){
    $.ajax({
     url:'index.php?entryPoint=check_email_template_subject',
                 data:{new_custom_data: custom_data},
                 success: function(data){
      if(data!= ''){
       document.getElementsByName("email_template_body_c")[0].value = data;
       SUGAR.util.callOnChangeListers(document.getElementsByName("email_template_body_c")[0]);
      }else{
       document.getElementsByName("email_template_body_c")[0].value = '';
       SUGAR.util.callOnChangeListers(document.getElementsByName("email_template_body_c")[0]);
      }
     }
    });
   } 
  }
}
 This is my code for tinymce editor textarea which is not working

function display_text(){
  if(typeof(document.getElementsByName('email_template_c')[0].value) != "undefined"){
   var custom_data = document.getElementsByName('email_template_c')[0].value;
   if(custom_data != ''){
    $.ajax({
     url:'index.php?entryPoint=check_email_template_subject',
                 data:{new_custom_data: custom_data},
                 success: function(data){
      if(data!= ''){
       $("p").parent(".mceContentBody").val(data);
       SUGAR.util.callOnChangeListers($("p").parent(".mceContentBody").val(data));
      }else{
       $("p").parent(".mceContentBody").val();
       SUGAR.util.callOnChangeListers($("p").parent(".mceContentBody").val());
      }
     }
    });
   } 
  }
}

And this is html code of tinymce editor texarea,

<html>
<head xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-COMPATIBLE" content="IE=7">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body dir="ltr" id="tinymce" class="mceContentBody" contenteditable="true">
<p>//Here should come email template body text
<br>
</p>
</body>
</html>

     So, Please guide me here on this.

Outcomes