Skip to main content

Notifications

Business Central forum
Answered

Purchase Line of Purchase Invoice validation Error

Posted on by 4
Hi all,
 
I have created a Job No. field on Purchase Header Table. I want to update /Job No./ and /Shortcut Dimension 1 Code/ fields on Purchase lines on Validation of JobNo. field of Purchase Header. I wrote the Code on Trigger OnValidate of JobNo. field of Purchase header to update /Job No./ and /Shortcut Dimension 1 Code/ fields on Purchase lines. But it is being updating the fields on purchase line when we close the Purchase Invoice Card Page and come back to page. Means it's not updating the value on purhcase lines immediately. 
please suggest answer. here is code
 
[EventSubscriber(ObjectType::Table, Database::/Purchase Header/, 'OnAfterValidateEvent', 'Job No.', false, false)]
    local procedure OnAfterValidateEvent(var Rec: Record /Purchase Header/; var xRec: Record /Purchase Header/)
    var
   Jobs: Record Job;
 PurchaseLine: Record /Purchase Line/;
 begin
        Jobs.Get(Rec./Job No./);
        Rec.Validate(/Shortcut Dimension 1 Code/, Jobs./Global Dimension 1 Code/);
        PurchaseLine.Reset();
        PurchaseLine.SetFilter(/Document Type/, '%1', Rec./Document Type/);
        PurchaseLine.SetRange(/Document No./, Rec./No./);
        if PurchaseLine.FindSet() then begin
            repeat
                PurchaseLine.Validate(/Job No./, Rec./Job No./);
                PurchaseLine.Validate(/Shortcut Dimension 1 Code/, Rec./Shortcut Dimension 1 Code/);
                PurchaseLine.Modify();
            
            until PurchaseLine.Next() = 0;
         
        end;
 
Categories:
  • Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 4,429 User Group Leader on at
    Purchase Line of Purchase Invoice validation Error
    Hi,
     
    Is your issue resolved?
    If yes, mark the answers that helped you as verified.
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Yi Yong Profile Picture
    Yi Yong 200 on at
    Purchase Line of Purchase Invoice validation Error
    MAHMOUDI's answer is correct but you will need to Validate instead of Assign on 'Shortcut Dimension 1 Code' otherwise the 'Dimension Set ID' may be incorrect.
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 4,429 User Group Leader on at
    Purchase Line of Purchase Invoice validation Error
    Hi,
     
    I think you can use the onValidate trigger in table extension.
    try this:
    tableextension 50110 "Purchase Header Ext" extends "Purchase Header"
    {
        fields
        {
            field(50101; "Job No."; code[20])
            {
                DataClassification = ToBeClassified;
    
                trigger OnValidate()
                var
                    PurchaseLine: Record "Purchase Line";
                begin
                    PurchaseLine.SetRange("Document Type", Rec."Document Type");
                    PurchaseLine.SetRange("Document No.", Rec."No.");
    
                    if PurchaseLine.FindSet() then
                        repeat
                            PurchaseLine."Job No." := Rec."Job No.";
                            PurchaseLine."Shortcut Dimension 1 Code" := Rec."Shortcut Dimension 1 Code";
                            PurchaseLine.Modify();
                        until PurchaseLine.Next() = 0;
                end;
            }
        }
    }
    Best regards,
    Mohamed Amine MAHMOUDI

Helpful resources

Quick Links

Upcoming TechTalk: Copilot Capabilities…

Review the Copilot features that are currently available in Dynamics 365 Finance…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,414 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,394 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans