Hello Everyone, I'm working on a ClientScript (Su...
# suitescript
j
Hello Everyone, I'm working on a ClientScript (SuiteScript 2.1) script that copies a Purchase Order and delete à line before saving. But I have an error on deleting the line. Could anyone help me find out what's wrong? PS : this is the error : Failed to remove line fais de mutation: Cannot read properties of undefined (reading 'itemType') Here’s the relevant part of my code:
try {
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); }