
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:
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?
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.
dynamicsuser.net/.../developers
I will open this up to the community in case they have something to add.
Thanks.