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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

E-mail Vendor Remittance from Payment Journal

(0) ShareShare
ReportReport
Posted on by 1,385

Dear Friends,

Need you help in sorting out my issue that I am facing.

I have few payment entries in Payment Journal for few Vendors (Account Type is Vendor in PJ).

Say,

VEND0001

VEND0002

VEND0003

VEND0004

VEND0005

Requirement: I need to send email to Vendors and Vendor Remittance report as attachment in it. I have placed a new option Email Remittance button in action tab of Payment Journal. On a single click email has to trigger for each Vendors with their corresponding Remittance.

Issue: I could able to send mail to Vendors as mentioned in the requirement. But the email attachment for all Vendors contains the Remittance of all the Vendors in new new page instead of attaching the corresponding Remittance to them. 

Report Dataitem: Gen. Journal Line

DataItemTableView Property: WHERE(Journal Batch Name=FILTER(AP-CA-PAYM),Journal Template Name=FILTER(PAYMENTS),Account Type=FILTER(Vendor))

Global Variables

pastedimage1595877484526v1.png

Function

LOCAL SendMailToVendWithAttachment(VendNo : Code[20)

locVendor.RESET;
locVendor.SETFILTER(locVendor."E-Mail", '%1', '*@*');
locVendor.SETRANGE(locVendor."No.", "Gen. Journal Line"."Account No.");
IF locVendor.FINDFIRST THEN BEGIN
    REPEAT
    
        CLEAR(SMTPMail);
        CLEARLASTERROR;
        
        SMTPSetup.GET;
        PdfDocPath := 'Remittance for '   locVendor.Name   '.pdf';
        Path := 'C:\Aarvi\PDFPath\Remittance'   PdfDocPath;
        //Path := FilePath   PdfDocPath;
        
        CLEAR(VendRemittance);
        VendRemittance.USEREQUESTPAGE(FALSE);
        VendRemittance.SETTABLEVIEW("Gen. Journal Line");
        VendRemittance.SAVEASPDF(Path);
        
        SMTPMail.CreateMessage('Company Name',SMTPSetup."User ID",
        locVendor."E-Mail",'Remittance for '   locVendor.Name ,'',TRUE);
        
        SMTPMail.AppendBody('Dear Sir/Madam,');
        SMTPMail.AppendBody('

'); SMTPMail.AppendBody('Please find the attachment of remittance herewith.'); SMTPMail.AppendBody('

'); SMTPMail.AppendBody('Regards,'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('Company Name'); SMTPMail.AppendBody('

'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('This is a system generated mail. Please do not reply to this email ID.'); SMTPMail.AddAttachment(Path,PdfDocPath); SMTPMail.Send; SLEEP(1000); ERASE(Path); UNTIL locVendor.NEXT = 0; END;

Calling the Function

Gen. Journal Line - OnAfterGetRecord()

SendMailToVendWithAttachment("Gen. Journal Line"."Account No.");

Can anyone tell me what am I missing here in the code?

Thanks in advance, Aarvi.

I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    on at

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

  • elmauro Profile Picture
    5 on at

    Hi Aarvi

    Same problem for me........Did u figured out ??????

  • arviax Profile Picture
    1,385 on at

    Hi elmauro,

    locVendor.RESET;

    locVendor.SETFILTER(locVendor."E-Mail", '%1', '*@*');

    locVendor.SETRANGE(locVendor."No.", "Gen. Journal Line"."Account No.");  // REMOVE THIS LINE AND CHECK

    IF locVendor.FINDFIRST THEN BEGIN

    ...

    ...

    ...

    Thanks, Aarvi.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,126

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 744 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 674 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans