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;
*This post is locked for comments
When I add your provided filter. Query is resolved. And it is fixed for purchase order only.
Thank you very much Murat sir.
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.
Here a little clue .
IF RecUserID.GET(RecAppEntry."Sender ID") AND (RecAppEntry."Table ID" = DATABASE::"Purchase Header") THEN
BEGIN
// SEND MAIL CODE
END
That is fine sir.
I want it works only for purchase order not for sales order. How to restrict in my code.
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
Sohail Ahmed
2
mmv
2
Amol Salvi
2