web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

JavaScript send data from dynamics crm per email

(0) ShareShare
ReportReport
Posted on by 249

hello everyone,

i try to get some details from dynamics crm (Phonecall entity) and to make this information in a body from an email. the problem is when have a multi line in the "description Field",  all the text will in one line wrote in the email body(see pictures). can anyone help me Thanks.

function TriggerOutlook()

    {
	//get the form value
	var form=Xrm.Page.ui.getFormType();
	//if the form is saved	
	 if(form==2)
	   {	

			// get the end date            
			var scheduledend = Xrm.Page.getAttribute("actualend").getValue();	                 
			var date =scheduledend.toString();
			var date_split = date.split(' ');
			switch(date_split[1])
			{
				case "Jan":
				var month="01";
				break;
				case "Feb":
				var month="02";
				break;
				case "Mar":
				var month="03";
				break;
				case "Apr":
				var month="04";
				break;
				case "May":
				var month="05";
				break;
				case "Jun":
				var month="06";
				break;
				case "Jul":
				var month="07";
				break;
				case "Aug":
				var month="08";
				break;
				case "Sep":
				var month="09";
				break;
				case "Okt":
				var month="10";
				break;
				case "Nov":
				var month="11";
				break;
				case "Dec":
				var month="12";
				break;
				
				
				
			}
			var end_Time=month "/" date_split[2] "/" date_split[3] ;
			
			
			var sub=Xrm.Page.getAttribute("subject").getValue() ;
			//get the description 
			var description = Xrm.Page.getAttribute("description").getValue();			
			
			
			//get the required Value
			var required  = Xrm.Page.data.entity.attributes.get("to").getValue();

		  
			//test of the empty fields
		  if (end_Time == null)
			{
				end_Time="";
			}
		  if(description == null)
			{
				description="";
			}
		 
			
			 if( required==null || required=="")

			{
				required="";
				
			}
			else
			{
				var required_name=required[0].name;
               var  required_id=required[0].id.toLowerCase();
                                
			}

			// trigger the Outlook
				var subject=required_name ", "  sub ;

				var body = "End Time:"   end_Time   escape('\n')   "Account:"   required_name  escape('\n')   "Contact:"   escape('\n')   "Description:"   description;       
				window.location.href = "mailto:?body=" body "&subject=" subject;               
	        
	    }
		
    }  

7128.email.JPG 

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Check following - stackoverflow.com/.../javascript-adding-linebreak-in-mailto-body

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Hedi,

    Could you share me your HTML code of description?

    As Andrew suggested, you can insert a line break with " ",

    you can replace link break symbol(<br>) by regex.

    For example, if actually there are many br tags in email body, then I can do replace job with code below:

    openEmail();
    
    function openEmail() {
      var body = Xrm.Page.getAttribute("description").getValue();
      var subject = "A test email";
      window.location.href = "mailto:?body="   parseHTML(body)   "&subject="   subject;
    }
    
    function parseHTML(htmlCode) {
      var text = htmlCode.replace(//gi, "
    ").replace(/] (>|$)/g, "")
      return text;
    }

    pastedimage1576747261838v1.png

    pastedimage1576747327473v3.png

    However, the final code would still depends on your HTML source code,

    because another possible situation is that your HTML looks like below:

    <div>1st Phone call descrption</div>

    <div>2st Phone call descrption</div>

    etc.

    a div element could be equivalent to a line.

    Then you should change regex:

    function parseHTML(htmlCode) {
      //var text = htmlCode.replace(//gi, "
    ").replace(/] (>|$)/g, "");
      var text = htmlCode.replace(/
    /g, "").replace(//g, " "); return text; }

    pastedimage1576748120289v4.png

    Please let me know whether it could helps.

    Regards,

    Clofly

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 29 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans