Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum

Adding a "Created by" field within purchase order

(0) ShareShare
ReportReport
Posted on by

I like to show "created by" and "last updated by" information on a purchase order. I believe that there is no built-in mechanism except customizing and extending Purchase Header. I appreciate if someone can provide any feedback on this. Thanks.

Categories:
  • mbharodia Profile Picture
    on at
    RE: Adding a "Created by" field within purchase order

    Okay Thanks. I also needed to update the code. I needed to call FindFirst() after setting the filter range as shown below. I believe that my issue was related with not calling FindFirst().

    local procedure SetPurchaseHeaderUpdateStatus(purchaseHeaderCode: Code[50])
        var
            purchaseHeader: Record "Purchase Header";
        begin
            purchaseHeader.SetRange("No.", purchaseHeaderCode);
            if purchaseHeader.FindFirst() then begin
                purchaseHeader."Last Updated By" := UserId();
                purchaseHeader."Last Updated On" := CurrentDateTime();
                purchaseHeader.Modify();
            end;
    
        end;


    With the above changes code works for both: adding a new line and updating existing lines. I am assigning value to purchaseHaderCode from Rec."Document No." while calling the above method from the triggers.

    Again many thanks for your help and support.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Adding a "Created by" field within purchase order

    I think you can remove the SetPurchaseHeaderUpdateStatus("Document No.") call from OnInsert trigger and leave only the call from OnModify.

  • mbharodia Profile Picture
    on at
    RE: Adding a "Created by" field within purchase order

    Okay. Thanks a lot for your reply. However, what's about OnModify() trigger? I believe that a header should be available within database during update of any purchase line. I tried with that too and I received the same error. Any suggestion … . Thanks.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Adding a "Created by" field within purchase order

    The SetPurchaseHeaderUpdateStatus is triggered in OnInsert trigger, do PurchaseHeader record is not yet wrote to the database and the MODIFY instruction will fail.

  • mbharodia Profile Picture
    on at
    RE: Adding a "Created by" field within purchase order

    I like to update "last updated by" field I added on purchase header every time there is a new purchase line added or updated. Therefore, I extended "Purchase Line" table and added the following code for OnInsert and OnModify triggers.

     trigger OnInsert()
        begin
            SetPurchaseHeaderUpdateStatus("Document No.");
        end;
    
        trigger OnModify()
        begin
            SetPurchaseHeaderUpdateStatus("Document No.");
        end;
    
        local procedure SetPurchaseHeaderUpdateStatus(purchaseHeaderCode: Code[50])
        var
            purchaseHeader: Record "Purchase Header";
        begin        
            purchaseHeader.SetRange("No.", purchaseHeaderCode);
            purchaseHeader."Last Updated By" := UserId();
            purchaseHeader."Last Updated On" := CurrentDateTime();
            purchaseHeader.Modify();
        end;


    I receive the following error.

    The purchase header does not exist. Identification field and values: Document Type: 'quote'; No.=''

    During debug time I see that "purchaseHeader" is being assigned; code runs fine till I call purcahseHeader.Modify(). It looks like that it might be failing after Modify () method is called. Additionally, I am also wondering why the error message refers to the document type of quote when I am trying to fetch a purchase header.

    I really appreciate if someone can help to resolve this issue.

  • Suggested answer
    mbharodia Profile Picture
    on at
    RE: Adding a "Created by" field within purchase order

    Okay. thanks.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Adding a "Created by" field within purchase order

    Yes, you need to:

    1) Create a tableextension object for Purchase Header and add the fields you need, with logic for inserting the value on that fields (OnInsert/OnModify trigger)

    2) Create a pageextension object and extends Purchase Order page for inserting that fields.

    Very simple to do.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,269 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans