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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Purchase Order

(0) ShareShare
ReportReport
Posted on by 1,893

Dear sir,

Now i have a one another concern

I want to send the all released po(in one wrking day) to the concern person..I have write the code in sendmail function in my purchase order page. And I m calling this function to codeunit for job que. But result is showing nothing...

please check my code sir, where I m doing mistake....

the complete code is :

Mail.CreateMessage('manish yadav','manish.yadav@mku.com','manish.yadav@mku.com','Purchase Order Statistics','',TRUE);

//Mail.AddCC('rakesh.gupta@mku.com');

//Mail.AddBCC('prachi.gupta@mku.com');

//Mail.AddAttachment('E:\UAT');

Mail.AppendBody('Dear Sir / Madam,');

Mail.AppendBody('<br>');

Mail.AppendBody('Please Approve this document,');

Mail.AppendBody('<br>');       //new

Mail.AppendBody('<HR>');       //new

Mail.AppendBody((STRSUBSTNO('Purchase Order No.:- %1, Order Date:- %2', Rec."No.", FORMAT(Rec."Order Date"))));

Mail.AppendBody('<br>');

Mail.AppendBody((STRSUBSTNO('Vendor Name:- %1', "Buy-from Vendor Name")));

Mail.AppendBody('<br><br>');

///////////////////////////////////////////

Mail.AppendBody('<table border="1">');

Mail.AppendBody('<tr>');

Mail.AppendBody('<th>Indent No.</th>');

Mail.AppendBody('<th>Item No.</th>');

Mail.AppendBody('<th>Item Description</th>');

Mail.AppendBody('<th>Quantity</th>');

Mail.AppendBody('<th>Unit</th>');

Mail.AppendBody('<th>Expected Receipt Date</th>');

Mail.AppendBody('<th>Promised Receipt Date</th>');

Mail.AppendBody('<th>Planned Receipt Date</th>');

Mail.AppendBody('</tr>');

/////////////////////////////////////////

CLEAR(DocNo);

recPurchaseHeader.RESET;

recPurchaseHeader.SETRANGE(recPurchaseHeader."Document Date", TODAY);

recPurchaseHeader.SETRANGE(recPurchaseHeader.Status, 1);  

IF recPurchaseHeader.FINDSET THEN BEGIN

DocNo:=recPurchaseHeader."No."

END;

PurchLine.RESET;

PurchLine.SETRANGE(PurchLine."Document No.", DocNo);

IF PurchLine.FINDSET THEN BEGIN

 REPEAT

 Mail.AppendBody('<tr>');

 Mail.AppendBody('<br>');

 Mail.AppendBody('<td>'+FORMAT(PurchLine."Requisition Document No.")+'</td>');

 Mail.AppendBody('<td>'+FORMAT(PurchLine."No.")+'</td>');

 Mail.AppendBody('<td>'+FORMAT(PurchLine.Description)+'</td>');

 Mail.AppendBody('<td align="right">'+FORMAT(PurchLine.Quantity)+'</td>');

 Mail.AppendBody('<td>'+FORMAT(PurchLine."Unit of Measure Code")+'</td>');

 Mail.AppendBody('<td>'+FORMAT(PurchLine."Expected Receipt Date")+'</td>');

 Mail.AppendBody('<td>'+FORMAT(PurchLine."Promised Receipt Date")+'</td>');

 Mail.AppendBody('<td>'+FORMAT(PurchLine."Planned Receipt Date")+'</td>');

 Mail.AppendBody('</tr>');

UNTIL PurchLine.NEXT = 0

END;

Mail.AppendBody('</table>');

Mail.AppendBody('<br>');

Mail.AppendBody('<HR>');

Mail.AppendBody('<br><br>');  

Mail.AppendBody('Regards');

Mail.AppendBody('<br>');

Mail.AppendBody('MKU Purchase Dept.');l.AppndBody('  ');

Mail.AppendBody('<br><br>');

Mail.Send;

MESSAGE('Mail Sent Successfully..!!!!');

___________________________________________________________

best regards,

manish

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at

    Hi,

    Is this code still in the page? It is prefered to move this code to a codeunit and call the codeunit from the page.

    Set the newly created codeunit's SingleInstance property to Yes.

    Then attach the codeunit in your job queue. Must work.

    Hope it helps.

  • Verified answer
    Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at

    Hi,

    Just one more suggestion on your code.

    You do not have to Mail.Append() so many times. You can concatenate the message into variables and append them.

    This way, your will be in fewer lines, clean and easy to read.

    Hope it helps.

  • Verified answer
    Community Member Profile Picture
    on at

    Create new codeunit and write the code as follow. Always, start with simple code and see if it works. Later you can all the fields.

    recPurchaseHeader.RESET;

    recPurchaseHeader.SETRANGE(recPurchaseHeader."Document Date", TODAY);

    recPurchaseHeader.SETRANGE(recPurchaseHeader.Status, 1);  

    IF recPurchaseHeader.FINDSET THEN

    Repeat

     Clear(Mail);

     Mail.CreateMessage('manish yadav','manish.yadav@mku.com','manish.yadav@mku.com','Purchase Order Statistics','',TRUE);

     PurchLine.RESET;

     PurchLine.SETRANGE("Document No.",recPurchaseHeader."No.");

     IF PurchLine.FINDSET THEN

     REPEAT

       Mail.AppendBody('<tr>');

       Mail.AppendBody('<br>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine."Document No.")+'</td>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine."Requisition Document No.")+'</td>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine."No.")+'</td>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine.Description)+'</td>');

       Mail.AppendBody('<td align="right">'+FORMAT(PurchLine.Quantity)+'</td>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine."Unit of Measure Code")+'</td>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine."Expected Receipt Date")+'</td>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine."Promised Receipt Date")+'</td>');

       Mail.AppendBody('<td>'+FORMAT(PurchLine."Planned Receipt Date")+'</td>');

       Mail.AppendBody('</tr>');

     UNTIL PurchLine.NEXT = 0

     Mail.Send;

    Until recPurchaseHeader.Next = 0;

  • Verified answer
    manish.yadav Profile Picture
    1,893 on at

    Dear Sir,

    I have applied the code as it is without any amendment.... We got the multiple mails.

    My concern is I want the all details in a single mail. Sir, is there any possibility to get the all Purchase Order details in a single mail.

    regards,

    manish

  • Verified answer
    Community Member Profile Picture
    on at

    Try this.

    You need to just keep the mail body outside the loop.

    Clear(Mail);

    Mail.CreateMessage('manish yadav','manish.yadav@mku.com','manish.yadav@mku.com','Purchase Order Statistics','',TRUE);

    recPurchaseHeader.RESET;

    recPurchaseHeader.SETRANGE(recPurchaseHeader."Document Date", TODAY);

    recPurchaseHeader.SETRANGE(recPurchaseHeader.Status, 1);  

    IF recPurchaseHeader.FINDSET THEN

    Repeat

    PurchLine.RESET;

    PurchLine.SETRANGE("Document No.",recPurchaseHeader."No.");

    IF PurchLine.FINDSET THEN

    REPEAT

      Mail.AppendBody('<tr>');

      Mail.AppendBody('<br>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine."Document No.")+'</td>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine."Requisition Document No.")+'</td>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine."No.")+'</td>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine.Description)+'</td>');

      Mail.AppendBody('<td align="right">'+FORMAT(PurchLine.Quantity)+'</td>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine."Unit of Measure Code")+'</td>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine."Expected Receipt Date")+'</td>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine."Promised Receipt Date")+'</td>');

      Mail.AppendBody('<td>'+FORMAT(PurchLine."Planned Receipt Date")+'</td>');

      Mail.AppendBody('</tr>');

    UNTIL PurchLine.NEXT = 0

    Until recPurchaseHeader.Next = 0;

    Mail.Send;

  • manish.yadav Profile Picture
    1,893 on at

    Now I get a single mail.

    u r great in the all over world.

    Thank you very much for super help.

    again thanks.

    manish.

  • manish.yadav Profile Picture
    1,893 on at

    0741.po.png

    here multiple line showing here.

    my new enhanced code here:


    CLEAR(Mail);
    Mail.CreateMessage('manish yadav','manish.yadav@mku.com','manish.yadav@mku.com','Purchase Order Statistics','',TRUE);

    Mail.AppendBody('Dear Sir / Madam,');
    Mail.AppendBody('<br><br>');
    Mail.AppendBody('Please Find The Purchase Order Details:');
    Mail.AppendBody('<br><br>'); //new

    Mail.AppendBody('<table border="1">');
    Mail.AppendBody('<tr>');

    Mail.AppendBody('<th>Purchase Order No.</th>');
    Mail.AppendBody('<th>Purchase Order Date</th>');
    Mail.AppendBody('<th>Vendor Name</th>');
    Mail.AppendBody('<th>Total Value</th>');
    Mail.AppendBody('<th>Unit</th>');
    Mail.AppendBody('</tr>');

    recPurchaseHeader.RESET;
    recPurchaseHeader.SETRANGE(recPurchaseHeader."Document Date", TODAY);
    recPurchaseHeader.SETRANGE(recPurchaseHeader.Status, 1);
    IF recPurchaseHeader.FINDSET THEN
    REPEAT
    PurchLine.RESET;
    PurchLine.SETRANGE("Document No.",recPurchaseHeader."No.");
    IF PurchLine.FINDSET THEN
    REPEAT
    Mail.AppendBody('<tr>');
    Mail.AppendBody('<br>');
    Mail.AppendBody('<td align="center">'+FORMAT(PurchLine."Document No.")+'</td>');
    Mail.AppendBody(' ');
    Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Order Date")+'</td>');
    Mail.AppendBody(' ');
    Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Buy-from Vendor Name")+'</td>');
    Mail.AppendBody(' ');
    Mail.AppendBody('<td align="right">'+FORMAT(PurchLine."Amount To Vendor")+'</td>');
    Mail.AppendBody(' ');
    Mail.AppendBody('<td align="center">'+FORMAT(PurchLine."Shortcut Dimension 1 Code")+'</td>');
    Mail.AppendBody(' ');

    Mail.AppendBody('</tr>');
    UNTIL PurchLine.NEXT = 0 ;
    UNTIL recPurchaseHeader.NEXT = 0;

    /////////////////////////////////

    Mail.AppendBody('</table>');
    Mail.AppendBody('<br><br>');
    Mail.AppendBody('Regards');
    Mail.AppendBody('<br>');
    Mail.AppendBody('MKU Purchase Departments ');
    Mail.AppendBody(' ');
    Mail.AppendBody('<br><br>');
    Mail.AppendBody('<HR>');

    //////////////////////////////////

    Mail.Send;
    //MESSAGE('Mail Sent Successfully..!!!!');

    Best regards,

    manish

  • Suggested answer
    Community Member Profile Picture
    on at

    Try this.

    CLEAR(Mail);

    Mail.CreateMessage('manish yadav','manish.yadav@mku.com','manish.yadav@mku.com','Purchase Order Statistics','',TRUE);

    Mail.AppendBody('Dear Sir / Madam,');

    Mail.AppendBody('<br><br>');

    Mail.AppendBody('Please Find The Purchase Order Details:');

    Mail.AppendBody('<br><br>'); //new

    Mail.AppendBody('<table border="1">');

    Mail.AppendBody('<tr>');

    Mail.AppendBody('<th>Purchase Order No.</th>');

    Mail.AppendBody('<th>Purchase Order Date</th>');

    Mail.AppendBody('<th>Vendor Name</th>');

    Mail.AppendBody('<th>Total Value</th>');

    Mail.AppendBody('<th>Unit</th>');

    Mail.AppendBody('</tr>');

    recPurchaseHeader.RESET;

    recPurchaseHeader.SETRANGE(recPurchaseHeader."Document Date", TODAY);

    recPurchaseHeader.SETRANGE(recPurchaseHeader.Status, 1);

    IF recPurchaseHeader.FINDSET THEN

    REPEAT

     recPurchaseHeader.Calcfields("Amount to Vendor");

     Mail.AppendBody('<tr>');

     Mail.AppendBody('<br>');

     Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Document No.")+'</td>');

     Mail.AppendBody(' ');

     Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Order Date")+'</td>');

     Mail.AppendBody(' ');

     Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Buy-from Vendor Name")+'</td>');

     Mail.AppendBody(' ');

     Mail.AppendBody('<td align="right">'+FORMAT(recPurchaseHeader."Amount To Vendor")+'</td>');

     Mail.AppendBody(' ');

     Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Shortcut Dimension 1 Code")+'</td>');

     Mail.AppendBody(' ');

     Mail.AppendBody('</tr>');

    UNTIL recPurchaseHeader.NEXT = 0;

    /////////////////////////////////

    Mail.AppendBody('</table>');

    Mail.AppendBody('<br><br>');

    Mail.AppendBody('Regards');

    Mail.AppendBody('<br>');

    Mail.AppendBody('MKU Purchase Departments ');

    Mail.AppendBody(' ');

    Mail.AppendBody('<br><br>');

    Mail.AppendBody('<HR>');

    //////////////////////////////////

    Mail.Send;

    //MESSAGE('Mail Sent Successfully..!!!!');

  • manish.yadav Profile Picture
    1,893 on at

    8712.po.png

  • Verified answer
    Community Member Profile Picture
    on at

    Check this.

    CLEAR(Mail);

    Mail.CreateMessage('manish yadav','manish.yadav@mku.com','manish.yadav@mku.com','Purchase Order Statistics','',TRUE);

    Mail.AppendBody('Dear Sir / Madam,');

    Mail.AppendBody('<br><br>');

    Mail.AppendBody('Please Find The Purchase Order Details:');

    Mail.AppendBody('<br><br>'); //new

    Mail.AppendBody('<table border="1">');

    Mail.AppendBody('<tr>');

    Mail.AppendBody('<th>Purchase Order No.</th>');

    Mail.AppendBody('<th>Purchase Order Date</th>');

    Mail.AppendBody('<th>Vendor Name</th>');

    Mail.AppendBody('<th>Total Value</th>');

    Mail.AppendBody('<th>Unit</th>');

    Mail.AppendBody('</tr>');

    recPurchaseHeader.RESET;

    recPurchaseHeader.SETRANGE("Document Date", TODAY);

    recPurchaseHeader.SETRANGE(Status, 1);

    IF recPurchaseHeader.FINDSET THEN

    REPEAT

    recPurchaseHeader.Calcfields("Amount to Vendor");

    Mail.AppendBody('<tr>');

    Mail.AppendBody('<br>');

    Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."No.")+'</td>');

    Mail.AppendBody(' ');

    Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Order Date")+'</td>');

    Mail.AppendBody(' ');

    Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Buy-from Vendor Name")+'</td>');

    Mail.AppendBody(' ');

    Mail.AppendBody('<td align="right">'+FORMAT(recPurchaseHeader."Amount To Vendor")+'</td>');

    Mail.AppendBody(' ');

    Mail.AppendBody('<td align="center">'+FORMAT(recPurchaseHeader."Shortcut Dimension 1 Code")+'</td>');

    Mail.AppendBody(' ');

    Mail.AppendBody('</tr>');

    UNTIL recPurchaseHeader.NEXT = 0;

    /////////////////////////////////

    Mail.AppendBody('</table>');

    Mail.AppendBody('<br><br>');

    Mail.AppendBody('Regards');

    Mail.AppendBody('<br>');

    Mail.AppendBody('MKU Purchase Departments ');

    Mail.AppendBody(' ');

    Mail.AppendBody('<br><br>');

    Mail.AppendBody('<HR>');

    //////////////////////////////////

    Mail.Send;

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans