Skip to main content

Notifications

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

  • manish.yadav Profile Picture
    1,893 on at
    RE: Filter problem in "Request To Approve" page.

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

    Thank you very much Murat sir.

  • Verified answer
    RobertasR Profile Picture
    5,002 on at
    RE: Filter problem in "Request To Approve" page.

    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.

  • Verified answer
    Muratvzr Profile Picture
    743 on at
    RE: Filter problem in "Request To Approve" page.

    Here a little clue .

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

    BEGIN

    // SEND MAIL CODE

    END

  • manish.yadav Profile Picture
    1,893 on at
    RE: Filter problem in "Request To Approve" page.

    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
    RE: Filter problem in "Request To Approve" page.

    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

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics NAV (Archived)

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2

#1
mmv Profile Picture

mmv 2

#1
Amol Salvi Profile Picture

Amol Salvi 2

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans