I'm trying to transform the SO to fulflliment requ...
# suitescript
s
I'm trying to transform the SO to fulflliment request and then to item fulfillment. I am able to create the fulfillment request but when I tried to create the item fulfillment, it is having an error: "You must enter at least one line item for this transaction." Any help would be apprciated. Below is my code.
let id = recSo.id;
let transformRecord = record.transform({
fromType: "salesorder",
fromId: id,
toType: "fulfillmentrequest",
isDynamic: true,
});
transformRecord.setValue({
fieldId: "transtatus",
value: "B",
});
let lineCount = transformRecord.getLineCount("item");
log.debug("Line Count", lineCount);
*for* (let i = 0; i < lineCount; i++) {
log.debug("i", i);
transformRecord.selectLine({
sublistId: "item",
line: i,
});
transformRecord.setCurrentSublistValue({
sublistId: "item",
fieldId: "itemreceive",
value: true,
});
transformRecord.commitLine({
sublistId: "item",
});
}
let fulfillReqId = transformRecord.save({
enableSourcing: true,
ignoreMandatoryFields: true,
});
log.debug("fulfillReqId", fulfillReqId);
*if* (fulfillReqId) {
// return true;
let fulfillReqRec = record.load({
type: "fulfillmentrequest",
id: fulfillReqId,
isDynamic: true,
});
let ifReqLoc = fulfillReqRec.getValue("location");
log.debug("soLoc", typeof soLoc);
let transformRToIF = record.transform({
fromType: "salesorder",
fromId: id,
toType: "itemfulfillment",
isDynamic: false,
defaultValues: {
inventorylocation: soLoc,
},
});
let lineCount = transformRToIF.getLineCount("item");
log.debug("Line Count", lineCount);
*for* (let i = 0; i < lineCount; i++) {
log.debug("i", i);
transformRToIF.selectLine({
sublistId: "item",
line: i,
});
transformRToIF.setCurrentSublistValue({
sublistId: "item",
fieldId: "itemreceive",
value: true,
line: i,
});
transformRToIF.commitLine({
sublistId: "item",
});
}
let ifReqId = transformRToIF.save({
enableSourcing: true,
ignoreMandatoryFields: true,
});
log.debug("ifReqId", ifReqId);