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

Community site session details

Session Id :
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.

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator 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.

  • Tony00001 Profile Picture
    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;

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

    I still need help, anyone?

  • Suggested answer
    Dallefeld Profile Picture
    211 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.....

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator 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?

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 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans