I'm encountering an issue in the SAP system, specifically when attempting to update the bin location. I'm getting the error code -4014, which says, "Cannot add row without complete selection of batch/serial numbers." This error occurs when I scan the bin, batch, and quantity in the FE (Front End) and try to submit the information. Below is the relevant code:
I'm not very familiar with the SAP system, and I'm seeking assistance in resolving this error. Specifically, I'd like to understand why the bin location is setting to null or zero in SAP. Any guidance on how to correct this issue would be greatly appreciated.
var http = require("HttpModule.js");
var PickList = require("EntityType/PickList.js");
var Order = require("EntityType/Document.js");
const BatchNumber = require("./ComplexType/BatchNumber");
const DocumentLinesBinAllocation = require("./ComplexType/DocumentLinesBinAllocation");
function GET() {
var slContext = new ServiceLayerContext();
var picklist = new PickList();
var order = new Order();
var param = http.request.getEntityKey();
picklist = slContext.PickLists.get(param);
if (!picklist.isOK()) {
throw new http.ScriptException(http.HttpStatus.HTTP_NOT_FOUND, "Picklist not found");
}
order = slContext.Orders.get(picklist.body.PickListsLines[0].OrderEntry);
if (!order.isOK()) {
throw new http.ScriptException(http.HttpStatus.HTTP_NOT_FOUND, "Order not found");
}
var ret = [];
var line = {
linenum: 0,
itemcode: 0,
batches: [],
bins: []
};
var lines = picklist.body.PickListsLines;
for (var i = 0; i < picklist.body.PickListsLines.length; i++) {
line.itemcode = order.body.DocumentLines[i].ItemCode;
for (var j = 0; j < picklist.body.PickListsLines[i].BatchNumbers.length; j++) {
line.batches.push({
"Batch Number": picklist.body.PickListsLines[i].BatchNumbers[j].BatchNumber,
"Quantity": picklist.body.PickListsLines[i].BatchNumbers[j].Quantity
});
}
for (var k = 0; k < picklist.body.PickListsLines[i].DocumentLinesBinAllocations.length; k++) {
line.bins.push({
"Bin Abs": picklist.body.PickListsLines[i].DocumentLinesBinAllocations[k].BinAbsEntry,
"Quantity": picklist.body.PickListsLines[i].DocumentLinesBinAllocations[k].Quantity
});
}
var copy = JSON.parse(JSON.stringify(line));
ret.push(copy);
line.linenum++;
line.itemcode = 0;
line.batches = [];
line.bins = [];
}
return http.response.send(http.HttpStatus.HTTP_OK, ret);
}
function POST() {
var slContext = new ServiceLayerContext();
var data = http.request.getJsonObj();
var order = new Order();
order = slContext.Orders.get(data.BaseEntry);
if (!order.isOK()) {
throw new http.ScriptException(http.HttpStatus.HTTP_NOT_FOUND, "Order not found");
}
var picklist = new PickList();
picklist = slContext.PickLists.get(data.picknum);
if (!picklist.isOK()) {
throw new http.ScriptException(http.HttpStatus.HTTP_NOT_FOUND, "PickList not found");
}
var line = order.body.DocumentLines[data.basedocline];
if (line.BatchNumbers.length > 0) {
var batches = line.BatchNumbers.find(b => b.BatchNumber == data.BatchNumber);
if (batches) {
for (var i = 0; i < order.body.DocumentLines.length; i++) {
order.body.DocumentLines[i].BatchNumbers = [];
}
batches.Quantity = data.quantity;
line.BatchNumbers.push(batches);
} else {
for (var i = 0; i < order.body.DocumentLines.length; i++) {
order.body.DocumentLines[i].BatchNumbers = [];
}
var batchline = new BatchNumber();
batchline.BatchNumber = data.BatchNumber;
batchline.Quantity = data.quantity;
line.BatchNumbers.push(batchline);
}
} else {
for (var i = 0; i < order.body.DocumentLines.length; i++) {
order.body.DocumentLines[i].BatchNumbers = [];
}
var batchline = new BatchNumber();
batchline.BatchNumber = data.BatchNumber;
batchline.Quantity = data.quantity;
line.BatchNumbers.push(batchline);
}
var pickline = picklist.body.PickListsLines[data.PickLine];
if (pickline.BatchNumbers.length > 0) {
var pickbatches = pickline.BatchNumbers.find(b => pickbatches.BatchNumber == data.BatchNumber);
if (pickbatches) {
for (var i = 0; i < picklist.body.PickListsLines.length; i++) {
picklist.body.PickListsLines[i].BatchNumbers = [];
}
pickbatches.Quantity = data.quantity;
pickline.BatchNumbers.push(pickbatches);
} else {
for (var i = 0; i < picklist.body.PickListsLines.length; i++) {
picklist.body.PickListsLines[i].BatchNumbers = [];
}
var batchline = new BatchNumber();
batchline.BatchNumber = data.BatchNumber;
batchline.Quantity = data.quantity;
batchline.BaseLineNumber = data.PickLine;
pickline.BatchNumbers.push(batchline);
}
} else {
for (var i = 0; i < picklist.body.PickListsLines.length; i++) {
picklist.body.PickListsLines[i].BatchNumbers = [];
}
var batchline = new BatchNumber();
batchline.BatchNumber = data.BatchNumber;
batchline.Quantity = data.quantity;
batchline.BaseLineNumber = data.PickLine;
pickline.BatchNumbers.push(batchline);
}
var sbline = 0;
if (pickline.DocumentLinesBinAllocations.length > 0) {
var pickbins = pickline.DocumentLinesBinAllocations.find(b => pickbins.BinAbsEntry == data.BinAbs);
sbline = pickline.DocumentLinesBinAllocations.length;
if (pickbins) {
for (var i = 0; i < picklist.body.PickListsLines.length; i++) {
picklist.body.PickListsLines[i].DocumentLinesBinAllocations = [];
}
pickbins.Quantity = data.quantity;
pickline.DocumentLinesBinAllocations.push(pickbins);
} else {
for (var i = 0; i < picklist.body.PickListsLines.length; i++) {
picklist.body.PickListsLines[i].DocumentLinesBinAllocations = [];
}
var docline = new DocumentLinesBinAllocation();
docline.BinAbsEntry = data.BinAbs;
docline.Quantity = data.quantity;
docline.BaseLineNumber = data.basedocline;
docline.SerialAndBatchNumbersBaseLine = parseInt(sbline);
pickline.DocumentLinesBinAllocations.push(docline);
}
} else {
for (var i = 0; i < picklist.body.PickListsLines.length; i++) {
picklist.body.PickListsLines[i].DocumentLinesBinAllocations = [];
}
var docline = new DocumentLinesBinAllocation();
docline.BinAbsEntry = data.BinAbs;
docline.Quantity = data.quantity;
docline.BaseLineNumber = data.basedocline;
docline.SerialAndBatchNumbersBaseLine = parseInt(sbline);
pickline.DocumentLinesBinAllocations.push(docline);
}
slContext.startTransaction();
var ret = [];
var res = slContext.Orders.update(order.body, data.BaseEntry);
if (!res.isOK()) {
ret.push(res.body);
ret.push(order.body);
slContext.rollbackTransaction();
return http.response.send(http.HttpStatus.HTTP_BAD_REQUEST, ret);
}
ret.push(res);
ret.push(order.body);
var res2 = slContext.PickLists.update(picklist.body, data.picknum);
if (!res2.isOK()) {
slContext.rollbackTransaction();
ret.push(res2);
ret.push(picklist.body);
return http.response.send(http.HttpStatus.HTTP_BAD_REQUEST, ret);
} else {
ret.push(res2);
ret.push(picklist.body);
slContext.commitTransaction();
return http.response.send(http.HttpStatus.HTTP_OK, ret);
}
}