Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Rejection mail to document creator.

(0) ShareShare
ReportReport
Posted on by 1,835

Dear All,

In approval time, is there any way we can send the Purchase order rejection mail to the Purchase order creator in Navision 2016. Please give me some idea to develop it.

*This post is locked for comments

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Rejection mail to document creator.

    Check whether you are getting email id in variable from User Setup table by using debugger..

  • manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: Rejection mail to document creator.

    I am trying with your suggestion but always, it is saying the "The email address is not valid.". What I am doing wrong in this code, firstly I am getting the email address from user setup and then after sending the email through page 654. In this page I have call the function(POrejectionConfirmation.) on reject button. on ribbon section.

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Rejection mail to document creator.

    Change the Code as below shown in Red Line which will resolve your error

    ApprovalEntry.RESET;

    ApprovalEntry.SETRANGE(ApprovalEntry."Approver ID", UserSetup."User ID");

    ApprovalEntry.SETRANGE(ApprovalEntry."Sender ID", UserSetup."User ID");

    IF ApprovalEntry.FINDFIRST THEN;

    // FOR PO Creator Email id

    IF UserSetup.GET(ApprovalEntry."Sender ID") THEN

     POCreatoremailid :=UserSetup."E-Mail";

    //FOR PO Approver email id  

    IF UserSetup.GET(ApprovalEntry."Approver ID") THEN

     POApproveremailid :=UserSetup."E-Mail";

           Mail.CreateMessage('MKU Limited','nav@abc.com','POApproveremailid','Purchase Order Rejection Notification','',TRUE);

    Mail.CreateMessage('MKU Limited','nav@abc.com',POApproveremailid,'Purchase Order Rejection Notification','',TRUE);

           Mail.AddCC(POCreatoremailid);        

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

           Mail.AppendBody('<br>');

           Mail.AppendBody('Rejected Purchase Order Details are below:');

           Mail.AppendBody('<HR>');

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

           Mail.AppendBody('<tr>');

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

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

           Mail.AppendBody('<th>Amount (LCY)</th>');

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

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

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

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

    ApprovalEntry.RESET;

    ApprovalEntry.SETRANGE(ApprovalEntry."Table ID",38);      

       IF ApprovalEntry.FINDSET THEN BEGIN

       REPEAT

        Mail.AppendBody('<tr>');

        Mail.AppendBody('<br>');

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

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

        Mail.AppendBody('<td align="right">'+FORMAT(ApprovalEntry."Amount (LCY)")+'</td>');    

       PurchaseHeader.RESET;

       PurchaseHeader.SETRANGE("No.", ApprovalEntry."Document No.");

      IF PurchaseHeader.FINDFIRST THEN BEGIN

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

      END;

        Mail.AppendBody('<td align="left">'+FORMAT(ApprovalEntry."Due Date")+'</td>');  

       ApprovalCommentLine.RESET;

       ApprovalCommentLine.SETRANGE("Document No.", ApprovalEntry."Document No.");

      IF ApprovalCommentLine.FINDFIRST THEN BEGIN

       Mail.AppendBody('<td align="left">'+FORMAT(ApprovalCommentLine.Comment)+'</td>');

      END;

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

       UNTIL ApprovalEntry.NEXT = 0;

       END;    

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

    Mail.AppendBody('<HR>');

    Mail.AppendBody('<br>');

    Mail.AppendBody('Regards');

    Mail.AppendBody('<br>');

    Mail.AppendBody('MKU Navision(ERP) System');

    Mail.AppendBody(' ');

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

    Mail.Send;

  • Tina Menezes Profile Picture
    Tina Menezes 2,576 on at
    RE: Rejection mail to document creator.

    Hi,

    You can create a new function in a codeunit with Event: Subscriber, EventPublisherObject: Codeunit Approvals Mgmt. and event function 'OnRejectApprovalRequest' and add the following code as shown in the below screenshot:

    Send-email.PNG

    You can read the following link to send email using C/AL code:

    https://saurav-nav.blogspot.in/2013/08/send-mail-with-attachment-from-navision.html?m=1

  • manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: Rejection mail to document creator.

    Dear Sir,

    I have prepared the code for this activity but it is always saying:

    4572.pic-01.png

    My written code is below:

    ApprovalEntry.RESET;

    ApprovalEntry.SETRANGE(ApprovalEntry."Approver ID", UserSetup."User ID");

    ApprovalEntry.SETRANGE(ApprovalEntry."Sender ID", UserSetup."User ID");

    IF ApprovalEntry.FINDFIRST THEN;

    // FOR PO Creator Email id

    IF UserSetup.GET(ApprovalEntry."Sender ID") THEN

     POCreatoremailid :=UserSetup."E-Mail";

    //FOR PO Approver email id  

    IF UserSetup.GET(ApprovalEntry."Approver ID") THEN

     POApproveremailid :=UserSetup."E-Mail";

           Mail.CreateMessage('MKU Limited','nav@abc.com','POApproveremailid','Purchase Order Rejection Notification','',TRUE);

           Mail.AddCC(POCreatoremailid);        

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

           Mail.AppendBody('<br>');

           Mail.AppendBody('Rejected Purchase Order Details are below:');

           Mail.AppendBody('<HR>');

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

           Mail.AppendBody('<tr>');

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

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

           Mail.AppendBody('<th>Amount (LCY)</th>');

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

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

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

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

    ApprovalEntry.RESET;

    ApprovalEntry.SETRANGE(ApprovalEntry."Table ID",38);      

       IF ApprovalEntry.FINDSET THEN BEGIN

       REPEAT

        Mail.AppendBody('<tr>');

        Mail.AppendBody('<br>');

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

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

        Mail.AppendBody('<td align="right">'+FORMAT(ApprovalEntry."Amount (LCY)")+'</td>');    

       PurchaseHeader.RESET;

       PurchaseHeader.SETRANGE("No.", ApprovalEntry."Document No.");

      IF PurchaseHeader.FINDFIRST THEN BEGIN

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

      END;

        Mail.AppendBody('<td align="left">'+FORMAT(ApprovalEntry."Due Date")+'</td>');  

       ApprovalCommentLine.RESET;

       ApprovalCommentLine.SETRANGE("Document No.", ApprovalEntry."Document No.");

      IF ApprovalCommentLine.FINDFIRST THEN BEGIN

       Mail.AppendBody('<td align="left">'+FORMAT(ApprovalCommentLine.Comment)+'</td>');

      END;

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

       UNTIL ApprovalEntry.NEXT = 0;

       END;    

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

    Mail.AppendBody('<HR>');

    Mail.AppendBody('<br>');

    Mail.AppendBody('Regards');

    Mail.AppendBody('<br>');

    Mail.AppendBody('MKU Navision(ERP) System');

    Mail.AppendBody(' ');

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

    Mail.Send;

  • Suggested answer
    RobertasR Profile Picture
    RobertasR 5,002 on at
    RE: Rejection mail to document creator.

    Hi

    Create an Event Subscriber for Codeunit 'Approvals Mgmt.', Event 'OnRejectApprovalRequest'. In this new function create a Notification that will be sent via dispatcher on Job Queue:

    NotificationEntry.CreateNew(NotificationEntry.Type::Approval,ApprovalEntry."Sender ID",ApprovalEntry,0,'');

    Here 'NotificationEntry' is the record 'Notification Entry'.

    You might also want to add checks that it's a PO, and not SO or journal.

    Hope that helps.

    Robertas

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans