Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Automatically due data by Payment Method Code

(0) ShareShare
ReportReport
Posted on by 50

Hi, i'm struggling with extension to Purchase/Sales Invoices. 

I added to "Payment Method Code", TableRealtion named "Type Payment" witch contain: "Document Date", "Order Date", "Posted Date", and "Sales Date".

The purpose is to automatically recalculate the due date when you select a specific "Payment Method Code". 

I tried to add it as an eventsub, but to no avail. It still only retrieves the document date automatically. Please help.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Automatically due data by Payment Method Code

    Your code looks a bit strange, so i agree with the question Kim is asking you. Why are you doing this, what are you really trying to achieve?

  • Suggested answer
    Dallefeld Profile Picture
    Dallefeld 11,425 User Group Leader on at
    RE: Automatically due data by Payment Method Code

    So your original post says that you added fields to Payment Method table but your code is referring to Payment Terms table. Two very different tables. Also, your code CalcDate(PaymentTerms."Due Data Calculation" should be Due Date not Due Data.

    But why are you doing this, Due Date is automatically recalculated if you change the payment terms.....

  • Tony00001 Profile Picture
    Tony00001 50 on at
    RE: Automatically due data by Payment Method Code

    I still need help, anyone?

  • Tony00001 Profile Picture
    Tony00001 50 on at
    RE: Automatically due data by Payment Method Code

    [EventSubscriber](ObjectType::Table, Database:: "Sales Header", 'OnValidatePaymentTermsCodeOnBeforeValidateDueData', '', false, false)

    local procedure PaymentTermsBeforeValidateDueData(CUrrentFieldNo: Integer; var IsHandled; var Sales Header: Record)

    begin

    SalesHeader.Validate(SalesHeader."Due Data", SalesHeader."Document Date");

    SalesHeader.Validate(SalesHeader."Due Data", SalesHeader."ITI Sales Date");

    SalesHeader.Validate(SalesHeader."Due Data", SalesHeader."Order Date");

    SalesHeader.Validate(SalesHeader."Due Data", SalesHeader."Posting Date);

    end;

    [EventSubscriber](ObjectType::Table, Database:: "Sales Header", 'OnValidatePaymentTermsCodeOnBeforeValidateCalcDueData', '', false, false)

    local procedure PaymentTermsBeforeCalcDueData(CalledByFieldNo: Integer; CallingFieldNo: Integer; var IsHandled: Boolean)

    var

    PaymentTerms: Record "Payment Terms";

    begin

    if PaymentTerms."Term Calculation Type Payment" = PaymentTerms."Term Calculation Type Payment::"Document Date" then

     SalesHeader."Due Data" := CalcDate(PaymentTerms."Due Data Calculation", SalesHeader."Document Date");

    if PaymentTerms."Term Calculation Type Payment" = PaymentTerms."Term Calculation Type Payment::"Order Date" then

     SalesHeader."Due Data" := CalcDate(PaymentTerms."Due Data Calculation", SalesHeader."Order Date");

    if PaymentTerms."Term Calculation Type Payment" = PaymentTerms."Term Calculation Type Payment::"Posting Date" then

     SalesHeader."Due Data" := CalcDate(PaymentTerms."Due Data Calculation", SalesHeader."Posting Date");

    if PaymentTerms."Term Calculation Type Payment" = PaymentTerms."Term Calculation Type Payment::"Sales Date" then

     SalesHeader."Due Data" := CalcDate(PaymentTerms."Due Data Calculation", SalesHeader."ITI Sales Date");

    end;

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Automatically due data by Payment Method Code

    I think you need to share the eventsubscriber code with us if we should be able to detect what can be wrong here.

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans