Hello, everyone.
I am trying to write a script that removes the Component list for an Assembly item and then adds items back on as I've specified. The functionality is happening in the BeforeSubmit function of a user event on Assembly Items, but I keep encountering issues and errors.
I thought that the correct code would be
var newRec = scriptContext.newRecord; util.each( itemsArray, function( value, index ) { var itemID = value[ itemID ]; var quantity = value[ quantity ]; newRec.selectNewLine({ sublistId: "member" }); newRec.setCurrentSublistValue({ sublistId: "member", fieldId: "item", value: itemID }); newRec.setCurrentSublistValue({ sublistId: "member", fieldId: "quantity", value: quantity }); newRec.commitLine({ sublistId: "member" }); });However, when I try this code, I get the following error:TypeError: Cannot find function selectNewLine in object DeferredDynamicRecord.The same happens for the setCurrentSublistValue and commitLine functions. Why can't I use these functions on a DeferredDynamicRecord?Another problem is that I need to remove all the current Component items before adding new ones, since the new list may have fewer items than the old one did. But when I add this code to my script: do { newRec.removeLine({ sublistId: "member", line: 0 }); } while( newRec.getLineCount({ sublistId: "member" }) > 0 ); I start getting Unexpected Errors on that line! Gah!Similarly, this thread mentioned a possible workaround, but the last post makes a good point. If the workaround isn't supported, then it's only a matter of time before it breaks, and I definitely don't want to have come in to find that one day. Also, since the workaround doesn't remove old entries, it doesn't do everything I need. Also, I really don't want to have to load the record that's already loaded using record.load, especially since I would then have to handle the user event script not getting stuck in an infinite loop when I submit that loaded record.Has anyone experienced this and found a solution? Am I missing something obvious?Thanks in advance.