Skip to main content

Notifications

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.

  • arviax Profile Picture
    1,385 on at
    RE: E-mail Vendor Remittance from Payment Journal

    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.

  • elmauro Profile Picture
    5 on at
    RE: E-mail Vendor Remittance from Payment Journal

    Hi Aarvi

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

  • Suggested answer
    Andy Sather Profile Picture
    on at
    RE: E-mail Vendor Remittance from Payment Journal

    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.

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 > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 756

#2
YUN ZHU Profile Picture

YUN ZHU 731 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 529

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans