hi guys.. anyone have a snippet on how to transfor...
# suitescript
b
hi guys.. anyone have a snippet on how to transform work order to completion? TIA 🫰 here's my code.. did i miss something?
Copy code
var completion= record.transform({
                fromType: record.Type.WORK_ORDER,
                fromId: 1234,
                toType: record.Type.WORK_ORDER_COMPLETION,
                isDynamic: true,
            });

            completion.setValue({
                fieldId: "quantity",
                value: 1,
                ignoreFieldChange: true,
            });

            var inventoryDetail= completion.getSubrecord({
                fieldId: "inventorydetail",
            });

            inventoryDetail.selectNewLine({
                sublistId: "inventoryassignment"
            });

            inventoryDetail.setCurrentSublistValue({
                sublistId: "inventoryassignment",
                fieldId: "quantity",
                value: 1, 
            });

            inventoryDetail.commitLine({
                sublistId: "inventoryassignment",
            });
            completion.selectLine({
                sublistId: "component",
                line: 3,
            });
            completion.setCurrentSublistValue({
                sublistId: "component",
                fieldId: "quantity",
                value: 10,
            });
            completion.commitLine({
                sublistId: "component"
            });
            completion.save(true, true);
n
No, what does the process involve?
b
Just transforming the work order to work order completion via script.. that's all 🙂
n
record.transform, go look at the help
b
Just need a sample of the needed fields etc.
n
message has been deleted
Right so you're saying that when you do record.tranform there's additional detail needs setting?
b
yahh.. but when I tried it.. it kept asking for the quantity for the component list.. while it only have one inventory detail
n
OK I see, so you need to figure out the logic to apply to have it save successfully. Sorry I don't have a snippet in that case, hopefully someone else can help.
👍 1
b
Thanks man.. Leaving the error message here in case someone already encountered it. Please provide values for the following fields in the Components list: Quantity
c
The error is telling you what to do...
b
Yah.. just need a sample snippet to follow... but might discover it later. Been hours trying to fix it as well..
here's my code.. did i miss something?
Copy code
var completion= record.transform({
                fromType: record.Type.WORK_ORDER,
                fromId: 1234,
                toType: record.Type.WORK_ORDER_COMPLETION,
                isDynamic: true,
            });

            completion.setValue({
                fieldId: "quantity",
                value: 1,
                ignoreFieldChange: true,
            });

            var inventoryDetail= completion.getSubrecord({
                fieldId: "inventorydetail",
            });

            inventoryDetail.selectNewLine({
                sublistId: "inventoryassignment"
            });

            inventoryDetail.setCurrentSublistValue({
                sublistId: "inventoryassignment",
                fieldId: "quantity",
                value: 1, 
            });

            inventoryDetail.commitLine({
                sublistId: "inventoryassignment",
            });
completion.selectLine({
                sublistId: "component",
                line: 3,
            });
            completion.setCurrentSublistValue({
                sublistId: "component",
                fieldId: "quantity",
                value: 10,
            });
            completion.commitLine({
                sublistId: "component"
            });
            completion.save(true, true);
n
You realise there's a "component" sublist on that record? You don't go anywhere near that sublist in your code snippet posted...
b
Let me update it.. tho i received the same error
n
You need to set the quantity on each component line I'd imagine based on the record sublist and your message
👍 1
b
Hmm.. does it really need to be each line?
Okays... but what if the work order issue only have the line 3 issued. And I like to create a completion for that line only... is it possible?
Really appreciate it 🙂
n
I'm afraid WO's/WOC's are not really anything I work with regularly but if you're not setting the value and it's expected, as per the message you're seeing then that's your issue.
c
Sounds like its complaining you aren't setting the quantity on the component line itself before diving into the detail/assignment. You set it on the header level but there's still the component level quantity that dictates how much to set on the assignment.
For each component (loop through them): 1. Set Component Line Level Quantity 2. Get Inventory Detail Subrecord for the Component and you can set the Item ID/Quantity there 3. Set the Inventory Detail Assignment sublist values you need
❤️ 1
💯 1
r
+1 for Chris Reece Answer. The NS errors are not specific enough. It could be the header qty, line qty or inv detail line qty. so log all and check them
👍 1
b
Thanks guys