Create new line CU400

rsfairbanksrsfairbanks Member Posts: 107
Hello,

I am using Code Unit 400 SMTP Mail and filling the message body, but I am not sure how to create a carriage return.

Example:
I am going though the sales order lines adding the item and quantity using the appendbody function, but I want each sales order line to appear on a new line of the email.

Any ideas please?

Sorted - used html - the answer always comes after you have asked a silly question :oops:

Mr Moderator: You are welcome to delete this posting!

Answers

  • WaldoWaldo Member Posts: 3,412
    A carriage return and line feed would have helped as well.

    Declare 2 variables (datatype = char): CR and LF.
    then do:
    CR := 13;
    LF := 10;

    Then, with FORMAT(CR) + FORMAT(LF), you "write" a carriage return.

    didn't test this, but it should work :|

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • MauddibMauddib Member Posts: 269
    I have a strange bug with this that I cant put my finger on.

    I have done exactly what was stated here and it works great. The return character enters.

    However I am doing this in a REPEAT UNTIL loop with two lines. The first code line adds a line to the email and the second code line adds the character return.

    However after about 30 lines the character return just stops working, meaning the email that is sent has all my lines of text in 30 lines then one big paragraph at the end.
  • WaldoWaldo Member Posts: 3,412
    And is it only in the mail application?

    Can you share some code?

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • MauddibMauddib Member Posts: 269
    SmtpMail.CreateMessage(EMAIL05, EMAIL06, EMAIL06, EMAIL05, '', FALSE);
    SmtpMail.AddBCC(EMAIL09);
    ReturnChar := 13;
    IF SharedItem.FINDSET THEN REPEAT
      PriceChange := ABS(SharedItem."Unit Price" - SharedItem."Old Price");
      SmtpMail.AppendBody(SharedItem."Item No." + ' ' + FORMAT(PriceChange);
      SmtpMail.AppendBody(FORMAT(ReturnChar));
    UNTIL SharedItem.NEXT = 0;
    
    SmtpMail.Send;
    

    Whether I receive this email in Outlook itself, or outlook over the web the result is the same. If I copy and paste the whole text block into WORD or notepad the result is the same.

    Basically I get a long list as expected and then suddely at a point around 30 lines down the result looks like the line:
    SmtpMail.AppendBody(FORMAT(ReturnChar));
    

    has just stopped working, giving me a big paragraph.
  • WaldoWaldo Member Posts: 3,412
    Just from the top of my head ... try this:
    SmtpMail.CreateMessage(EMAIL05, EMAIL06, EMAIL06, EMAIL05, '', FALSE); 
    SmtpMail.AddBCC(EMAIL09); 
    LineFeed := 10;
    CarriageReturn := 13; 
    IF SharedItem.FINDSET THEN REPEAT 
      PriceChange := ABS(SharedItem."Unit Price" - SharedItem."Old Price"); 
      SmtpMail.AppendBody(SharedItem."Item No." + ' ' + FORMAT(PriceChange); 
      SmtpMail.AppendBody(FORMAT(CarriageReturn) + FORMAT(LineFeed)); 
    UNTIL SharedItem.NEXT = 0; 
    
    SmtpMail.Send;
    

    "CarriageReturn" and "LineFeed" are variables with datatype "Char".

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • MauddibMauddib Member Posts: 269
    I tried that exact change and it made no difference.

    However as I tested it so soon after it ran normally in my scheduler there was only a few entries in the email this time. 10 to be exact. This time the problem occoured after the 2nd line. So lines 3 to 10 were all in one big paragraph.

    Seems to be something to do with being near the end of the list, and nothing to do with long lists etc.
  • WaldoWaldo Member Posts: 3,412
    Have you tested it by writing it to a txt-file - or just something else then a mail?

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • MauddibMauddib Member Posts: 269
    Yes, this process used to write to a text file and I have just moved it into a mail. In the test file the issue never occured.

    Weird huh?
  • WaldoWaldo Member Posts: 3,412
    Yeah, sorry, I've never seen this happening.

    I've been working with text quite a lot (thanks to my NavPad), but this issue ... :-k

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • markborgesmarkborges Member Posts: 170
    Not sure if this is still a problem for the author, but I was having the exactly same issue, and I found out that Outlook was the one, sneaky, removing the "Extra Line Breaks".... So it was making that weird junk paragraph at the end of the list.
    Marcelo Borges
    D365 Business Central Solutions Architect
    BC AL/NAV C/AL Developer
    BC Repositories.com
Sign In or Register to comment.