Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Automatically due data by Payment Method Code

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.

Categories:
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 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?

  • Suggested answer
    Dallefeld Profile Picture
    Dallefeld 11,423 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,744 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.

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,564 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,651 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans