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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Filter problem in "Request To Approve" page.

(0) ShareShare
ReportReport
Posted on by 1,893

Dear Experts, 

I have make a code for send a notification to user, if Purchase order is rejected. This code is applied on "Request to Approve" page on "Reject Button". I am unable to filter the purchase order here. Because, if any sales order is rejected then the same mail is going to sales order creator person. What i need to add the extra filter here? Please help me. This code is work only for "Purchase order document" only not for sales order.

My code is below.

RejectionMailtoSendor(VAR RecAppEntry : Record "Approval Entry")
AE.RESET;
AE.SETRANGE("Document Type",RecAppEntry."Document Type");
AE.SETRANGE("Document No.",RecAppEntry."Document No.");
AE.SETRANGE(AE."Table ID", 38);
AE.FINDFIRST;

IF RecUserID.GET(RecAppEntry."Sender ID") THEN;
Mail.CreateMessage('MKU Limited','nav-uat@mku.com','','Rejected PO No.: '+ RecAppEntry."Document No.",'',TRUE);
Mail.AppendBody('Dear Sendor,');
Mail.AppendBody('<br><br>');
Mail.AppendBody('Your Purchase Order has been rejected, please read the comment carefully:');
Mail.AppendBody('<br>');
Mail.AppendBody('<table border="1">');
Mail.AppendBody('<tr>');
Mail.AppendBody('<th>PO No.</th>');
Mail.AppendBody('<th>Comments</th>');
Mail.AppendBody('</tr>');

IF RecUserID.GET(RecAppEntry."Sender ID") THEN
Mail.AddCC(RecUserID."E-Mail");

AE.RESET;
AE.SETRANGE("Document Type",RecAppEntry."Document Type");
AE.SETRANGE("Document No.",RecAppEntry."Document No.");

IF AE.FINDLAST THEN BEGIN
REPEAT
Mail.AppendBody('<tr>');
Mail.AppendBody('<br>');
Mail.AppendBody('<td align="left">'+FORMAT(AE."Document No.")+'</td>');

ApprovalCommentLine.RESET;
ApprovalCommentLine.SETRANGE("Document No.", AE."Document No.");
IF ApprovalCommentLine.FINDLAST THEN BEGIN
Mail.AppendBody('<td align="left">'+FORMAT(ApprovalCommentLine.Comment)+'</td>');
END;

Mail.AppendBody('</tr>');
UNTIL AE.NEXT = 0;
END;

Mail.AppendBody('</table>');
Mail.AppendBody('<br>');
Mail.AppendBody('Regards');
Mail.AppendBody('<br>');
Mail.AppendBody('MKU Navision(ERP) System');
Mail.AppendBody(' ');
Mail.AppendBody('<br><br>');
Mail.Send;

2744.test01.png

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Muratvzr Profile Picture
    743 on at

    I assume you have function on this page and you wrote the whole function on here.

    First try this. When you are calling your function. you send Rec variable to this function.

    Current Rec is your approval entry record you dont need to filter it.

    RejectionMailtoSendor(VAR RecAppEntry : Record "Approval Entry")

    IF RecUserID.GET(RecAppEntry."Sender ID") THEN

    BEGIN

    // SEND MAIL CODE

    END

    if you want to add more detail than add record variables and filter them by RecAppEntry

  • manish.yadav Profile Picture
    1,893 on at

    That is fine sir.

    I want it works only for purchase order not for sales order.  How to restrict in my code.

  • Verified answer
    Muratvzr Profile Picture
    743 on at

    Here a little clue .

    IF RecUserID.GET(RecAppEntry."Sender ID") AND (RecAppEntry."Table ID" = DATABASE::"Purchase Header")  THEN

    BEGIN

    // SEND MAIL CODE

    END

  • Verified answer
    RobertasR Profile Picture
    5,004 on at

    Hi, your code fails on 'AE.FINDFIRST'. If you change it to be:

    IF AE.FINDFIRST THEN BEGIN

    /... all your current code here up until Mail.Send/

    END;

    then it should be fine.

  • manish.yadav Profile Picture
    1,893 on at

    When I add your provided filter. Query is resolved. And it is fixed for purchase order only.

    Thank you very much Murat sir.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

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