Is there a server side method to create a work ord...
# suitescript
e
Is there a server side method to create a work order from a sales order, like one would by clicking the work order link on the item sublist?
record.transform
isn't supported, and using
defaultValues
doesn't work either.
b
which default values did you try
e
assemblyItem (which is fine) and soid
well, pretty much all of them from the UI, actually
Copy code
defaultValues: {
                                        soid: productionInfo.custrecordunit_salesorder,
                                        soline: 1, // Update this to the correct line number.
                                        specord: 'T',
                                        entity: entity,
                                        assemblyitem: nextModel.internalid,
                                          quantity: 1,
                                          location: location
                                    }
b
not all those are default values
add them one at a time to figure out which ones arent
👍 1
you should get an error about invalid default values for ones that arent
e
The word order is created, but not linked, the
createdfrom
is empty, I'm going to guess nothing can be done about that?
b
what does the code look like
e
Copy code
const workOrderRec = record.create({
                                    type: record.Type.WORK_ORDER,
                                    isDynamic: true,
                                    defaultValues: {
                                        assemblyitem: nextModel.internalid,
                                        soid: productionInfo.custrecordunit_salesorder,
                                        soline: oldModelLine,
                                        specord: 'T'
                                    }
                                });
                                workOrderRec.setValue('custbodydealer', entity);
                                workOrderRec.setValue('entity', entity);
                                workOrderRec.setValue('custbodyunit', productionInfo.id);
                                workOrderRec.setValue('quantity', 1);
                                workOrderRec.setValue('location', location);
                                const workOrderId = workOrderRec.save();
Ids are fine and valid
b
dont set the entity
e
Did that and also tried standard mode, same thing
b
you may want to make the work order in the ui and then compare the two in script to see which fields are different
usually related records becoming unlinked involves modifying fields the related fields between the two, so will also want to make sure there are no user event scripts or workflows making changes
e
Ah true, alright. Thanks!