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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Bringing the field (data) from sales order to purchase order using Code Unit in Business Central

(0) ShareShare
ReportReport
Posted on by 254

Hi Members,

I need to bring a field (data) from sales order to the purchase order using the Codeunit in Business Central. Please suggest me an appropriate solution - with code (using AL code) for the problem.

Thanks and Regards,

Saravanan M

I have the same question (0)
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Do you want to create new fields on the purchase order table or will you be putting the data into existing fields.

    And do you have some examples of the fields you want to collect from the sales order?

  • Suggested answer
    YUN ZHU Profile Picture
    102,476 Super User 2026 Season 1 on at

    Hi, I think it depends on how you create the purchase order.

    If you create a purchase order from Drop Shipments or Special Order, you need to add the code to the relevant event.

    pastedimage1660437875543v1.png

    If you create a purchase order from a sales order, you need to add code to this process.

    pastedimage1660437899587v2.png

    If you are creating purchase orders manually, you need to add the associated step actions.

    Although these instructions are not very specific, I hope they will give you some hints.

    Thanks.

    ZHU

  • M Saravanan Profile Picture
    254 on at

    Dear Inge M.Bruvik,

    I am trying to bring an extisting field(value) from Sales Order to the Purchase Order. I am looking for a solution to pass a value from the Sales Order and assign the value to a field in Purchase Order. Please do help me out by providing me an appropriate solution to problem.

    Thanks and Regards,

    Saravanan M

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Please use OnCreatePurchaseOrderOnAfterPurchaseHeaderSetFilters event from codeunit 1314 "Purch. Doc. From Sales Doc.",

    It will help you transfer Sales fields to Purchase header table.

    Thanks.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Hi M Saravanan

    If you want to do this as a part of the standard functionality for creating purchase order from a sales order you should use the

    OnCreatePurchaseHeaderOnBeforeInsert event on codeunit 1314 "Purch. Doc. From Sales Doc.

    There you have access to both the sales order and the purchase order.

    If you want to pass field to an existing purchase order you will have to decide if it should happen manually. Have the user click on a menu item or if it should happen automatically either when something happens on the sales order or you want a timer based job that keeps all purchase orders updated.

  • Suvarna Profile Picture
    on at

    Hi Saravanan,

    R u able to do this? Even I also want to pull external document no from sales order into vendor invoice no in purchase order. If u r able to do then please help me with code part? How to do it in VS.

  • Verified answer
    Lakshmanan.R Profile Picture
    137 on at

    Dear suvarna,

    Yes, I am able to achieve this. I am hereby attaching the code along with this message. I am sure that the code would work efficiently for you in achieveing your requirement.

    codeunit 50133 SOtoPO

    {

       [EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Doc. From Sales Doc.", 'OnCreatePurchaseOrderOnAfterPurchaseHeaderSetFilters', '', false, false)]

       local procedure Salesordertopurchaseordermessage(SalesHeader: Record "Sales Header"; PurchaseHeader: Record "Purchase Header")

       begin

           PurchaseHeader."Vendor Order No." := SalesHeader."External Document No.";

           PurchaseHeader.Modify(true);

       end;

    }

    Thanks and Regards,

    Lakshmanan R

  • Suvarna Profile Picture
    on at

    Hi Lakshmanan,

    Thank you very much. This is working.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 702 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 481 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 328 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans