Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

JavaScript send data from dynamics crm per email

Posted on by 235

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 

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: JavaScript send data from dynamics crm per email

    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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: JavaScript send data from dynamics crm per email

    Hello,

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans