Search code examples
netsuitesuitescriptsuitescript2.0

Items Missing when creating Purchase Order with Dropship Default Values


I am trying to create a Dropship Purchase Order via SuiteScript 2. I am able to create the Purchase order object with the correct Drop ship data (customer, Sales order, Dropship form) however I get the following error when saving

"You must enter at least one line item for this transaction.".

I can manually create the drop ship from the Sales Order and the items add fine. I am using Netsuite OneWorld.

Below is the code I'm using

var purchaseOrder = record.create({
                type: record.Type.PURCHASE_ORDER,
                isDynamic: true,
                defaultValues: {
                    soid: 4427821,
                    dropship: true,
                    subsidiary: 9,
                    custid: 666,
                    entity: 322
                }
});
purchaseOrder.setValue({
    fieldId: "employee",
    value: 3
});
    
log.debug("Item Count", purchaseOrder.getLineCount("item"));
log.debug("Entity", purchaseOrder.getText("entity"));
log.debug("Customer", purchaseOrder.getText("shipto"));
log.debug("Sales Order", purchaseOrder.getText("createdfrom"));
log.debug("Form", purchaseOrder.getText("customform"));
log.debug("Subsidiary", purchaseOrder.getText("subsidiary"));
    
purchaseOrder.save();

Here some screengrabs as well

Sales Order

Manual Drop Ship PO

Script Logs

I have existing scripts that create standalone POs, so I have some idea of the process required here. Is there a step I'm missing for Dropships specifically? I found this thread in which Will Charbonneau said this should be all you need Netsuite: How to link Purchase Order to Sales Order. I've tried Their code with my IDs, and it results in the same error.


Solution

  • So in case anyone is still having trouble with this, I figured it out.

    var purchaseOrder = record.create({
                type: record.Type.PURCHASE_ORDER,
                isDynamic: true,
                defaultValues: {
                    customform: 180, //dropship custom form
                    soid: 4820583, //Sales order internalID
                    shipgroup: 1, //from 'dropship' button url via UI
                    dropship: true, //from 'dropship' button url via the UI
                    custid: 666, //customer InternalID
                    entity: 322, //vendor InternalID
                    poentity: 322 //vendor InternalID
                }
            });
    var poid = purchaseOrder.save();
    

    I don't know why half of these fields are not documented anywhere (defaultvalues or the schema) but this auto populates the items and customer details just like it would via the UI.