Jean Paul Soro
02/13/2025, 10:43 AMtry {
console.log("between", poId);
var copiedPurchaseOrder = record.copy({
type: record.Type.PURCHASE_ORDER,
id: poId,
isDynamic: true,
});
copiedPurchaseOrder.setValue({
fieldId: "location",
value: selectedLocation,
ignoreFieldChange: true,
fireSlavingSync: true,
});
// Set the user
copiedPurchaseOrder.setValue({
fieldId: "recordcreatedby",
value: currentUser,
ignoreFieldChange: true,
fireSlavingSync: true,
});
copiedPurchaseOrder.setValue({
fieldId: "memo",
value: memoText,
ignoreFieldChange: true,
fireSlavingSync: true,
});
console.log("location", selectedLocation);
console.log("after", poId);
var purchaseNewId = copiedPurchaseOrder.save();
var newPO = record.load({
type: record.Type.PURCHASE_ORDER,
id: purchaseNewId,
isDynamic: true,
});
var newPoTranId = newPO.getValue({
fieldId: "tranid",
});
const lineCount = newPO.getLineCount({
sublistId: "item",
});
try {
if (lineCount > 0) {
newPO.selectLine({ sublistId: "item", line: 3 });
newPO.removeLine({
sublistId: "item",
line: 3,
ignoreRecalc: true,
});
console.log("Line removed successfully");
}
} catch (error) {
console.log("Failed to remove line: " + error.message);
}
newPO.save({
enableSourcing: true,
ignoreMandatoryFields: true,
});
} catch (copyError) {
console.error("Error copying Purchase Order:", copyError);
}