Skip to Content
0

B1 DI API changing Batch Number on Delivery?

Sep 10, 2017 at 09:50 AM

391

avatar image
Former Member

We had a situation where there was a big screw up in the warehouse and the batch number selected for multiple orders isn't actually available to ship. I'm trying to find a way to programmatically modify the existing Delivery documents because cancelling and reissuing them will cause headaches elsewhere in the company workflow.. I have tried several different attempts so far with no luck. All of the deliveries are open, no lines shipped or invoiced.

Attempt 1, Change BatchNumber:

Company oCompany    = new SAPbobsCOM.Company();
/// company configuration here...
Documents doc    = oCompany.GetBusinessObject((int)BoObjectTypes.oDeliveryNotes);

doc.GetByKey(docEntry);

doc.Lines.BatchNumbers.BatchNumber = newBatchNumber;
doc.Update();

Update() returns 0 and no error codes is given, but batch number has not actually changed when I check afterwards.

Attempt 2, Delete Original Line, Add New Line:

// using same oCOmpany and doc init as #1
// get values from existing line    
doc.Lines.SetCurrentLine(0);
int BaseEntry           = doc.Lines.BaseEntry;
int BaseType            = doc.Lines.BaseType;
int BaseLine            = doc.Lines.BaseLine;
string ItemCode         = doc.Lines.ItemCode;
double Quantity         = doc.Lines.Quantity;
string FreeText         = doc.Lines.FreeText;

int UoMEntry            = doc.Lines.UoMEntry;
double Price            = doc.Lines.Price;
string WarehouseCode    = doc.Lines.WarehouseCode;

// delete old line
doc.Lines.Delete();

// add new line
doc.Lines.Add();
// assign same values as deleted line
doc.Lines.BaseEntry                 = BaseEntry;
doc.Lines.BaseType                  = BaseType;
doc.Lines.BaseLine                  = BaseLine;
doc.Lines.ItemCode                  = ItemCode;
doc.Lines.Quantity                  = Quantity;
doc.Lines.FreeText                  = FreeText;
doc.Lines.UoMEntry                  = UoMEntry;
doc.Lines.Price                     = Price;
doc.Lines.WarehouseCode             = WarehouseCode;
doc.Lines.BatchNumbers.BatchNumber  = newLot;
doc.Lines.BatchNumbers.Quantity     = Quantity;
doc.Update();

Throws Error -5002: Item number is missing; specify an item number {DLN1.ItemCode][Line: 1]

Attempt 3, Add New Line, then Delete Original Line:

// Same Copy Values and Add Line as Attempt 2

// delete old line
doc.Lines.SetCurrentLine(0);
doc.Lines.Delete();
doc.Update();

Throws Error -5002: 10001221 - Specify "Items per Unit" greater than zero [INV1.NumPerMsr][line: 1]

Attempt 4, Add New Line, Zero Out Original Line:

// Same Copy Values and Add Line as Attempt 2

// zero out old line
doc.Lines.SetCurrentLine(0);
this.doc.Lines.BaseEntry            = 0;
doc.Lines.BaseType                  = 0;
doc.Lines.BaseLine                  = 0;
doc.Lines.Quantity                  = 0;
doc.Lines.BatchNumbers.Quantity     = 0;
doc.Update();

Throws Error -5002: Item number is missing; specify an item number {DLN1.ItemCode][Line: 1]

I'm not sure why its giving the missing item error in #2 & #4, if I print doc.Lines.ItemCode before Update() it gives the correct value. I would be very grateful for any help getting this working.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

DIEGO LOTHER Sep 15, 2017 at 03:13 AM
1

Hi Chris,

I believe that not exist any way to change batch on delivery or invoice. Neither by the SDK nor by client.

Possible solutions, look this:

https://archive.sap.com/discussions/thread/3686536

Hope it helps.

Kind Regards,

Diego Lother

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you for the link. That is unfortunate, seems silly that you can't edit the batch numbers if the delivery has not been closed or invoiced. I wish the error codes thrown would actually make it clear if the action is forbidden rather than a misleading error about itemcodes or units.

0