Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Add item tracking to purchase order via webservice

(0) ShareShare
ReportReport
Posted on by 27

I'm trying to add item tracking to a purchase order using a webservice (api pages).

After some digging and searching I found  that this is done through adding a record to Table 337 (Reservation Entry)

So I exposed this table to the webservice using an api page in AL, and now I could send the following request to my webservice:

POST /itemTrackingReservations? HTTP/1.1
Host: 
Content-Type: application/json

{
    "@odata.etag": "W/\"JzQ0O0VBcmk1K0h6cVBLR3BpWDl4UldaZzV5eHc4TzNWRW9ZSStjWWJHaTVvbXM9MTswMDsn\"",
    "itemNo": "1000",
    "locationCode": "STD-MAG",
    "quantityBase": 2,
    "reservationStatus": "Surplus",
    "creationDate": "2020-04-06",
    "sourceType": 39,
    "sourceSubtype": "1",
    "sourceID": "106006",
    "sourceRefNo": 10000,
    "sourceBatchName": "",
    "expectedReceiptDate": "2020-05-01",
    "serialNo": "SN1",
    "Quantity": 1,
    "lotNo": ""
}

At first glance and testing this worked fine.

However, things started going wrong when I did not complete all items on the line in one go, but in multiple goes (for example, add 2 of the 5 serial numbers and then post the line).

After posting a partial line, the tracking information shows the following:
pastedimage1595418790030v1.png

Which for serial numbers should be impossible. As expected, BC does not allow me to post the purchase order in this state.

So now I'm looking for some other way to add the serial numbers to the purchase order. I already found https://community.dynamics.com/nav/f/microsoft-dynamics-nav-forum/186214/how-to-create-item-tracking-line-from-c-al and I tried the code in there as follows for testing:

action(AddItemTracking)
            {
                ApplicationArea = All;
                Image = Track;
                Caption = 'Add Item Tracking';

                trigger OnAction()
                var
                    reservationManagement: Codeunit "Reservation Management";
                    purchLineReserve: Codeunit "Purch. Line-Reserve";
                    reservationEntry: Record "Reservation Entry";
                    trackingSpecification: Record "Tracking Specification";
                    doFullReserve: Boolean;
                begin
                    reservationManagement.SetReservSource(Rec);
                    reservationManagement.AutoReserve(doFullReserve, Rec.Description, WorkDate(), 1, 1);
                    reservationManagement.SetSerialLotNo('SN1001', '');
                    Message('%1', trackingSpecification.Count);
                    Rec.SetReservationFilters(reservationEntry);
                    Message('%1', reservationEntry.Count);
                end;

            }

However, no reservation lines are created. What is the correct way to add item tracking to a purchase order using the webservice? What code units and functions should I use?

If I want to also correctly implement this for Sales Orders, what are the important differences in my code?

  • Suggested answer
    Marco Mels Profile Picture
    on at
    RE: Add item tracking to purchase order via webservice

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans