I'm working on a ClientScript (SuiteScript 2.1) sc...
# suitescript
j
I'm working on a ClientScript (SuiteScript 2.1) script that copies a Purchase Order and delete a line before saving. But I have an error on deleting the line. Could anyone help me find out what's wrong? Here’s the relevant part of my code:
r
The relevant part of code seems a bit empty, that might be the issue 😅
j
Sorry 🤣 : PS : this is the error : Failed to remove line fais de mutation: Cannot read properties of undefined (reading 'itemType') Here's 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); }
🤣 1
n
Do you have 4 lines? You're working with line 3 (0,1,2,3) You also don't seem to be referencing itemType in this snippet unless I'm being blind.
e
I don't see
itemType
either
j
I am not referencing ItemType but this is the error i get. Don't know why
lineCount on the record is always 4