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.

  • arviax Profile Picture
    arviax 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
    elmauro 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
    Andy Sather 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 Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans