Reputation: 1
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
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.
Upvotes: 0
Views: 683
Reputation: 1
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.
Upvotes: 0
Reputation: 696
I was able to reproduce the same error you had, and the code below shows the solution. This was tested successfully in the Script Debugger.
require(['N/record', 'N/log'],
function(record, log) {
var purchaseOrder = record.create({
type: record.Type.PURCHASE_ORDER,
isDynamic: true,
defaultValues: {
soid: 1 /* random sales order */,
dropship: true,
subsidiary: 1 /* the one and only in my account */,
custid: 4 /* Entity Internal ID for Customer: Powerslide */,
entity: 10 /* Entity Internal ID for Vendor: Salesforce */
}
});
purchaseOrder.setValue({
fieldId: "employee",
value: 3 /* me */
});
// -----
// BEGIN: Add a line to the purchase order, so as to avoid the error,
// "You must enter at least one line item for this transaction"
// -----
purchaseOrder.selectNewLine({
sublistId: 'item'
});
purchaseOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 6 /* Non-inventory Item for Purchase */
});
purchaseOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 1
});
purchaseOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value: 10000 /* casual $10k */
});
purchaseOrder.commitLine({sublistId: 'item'});
// -----
// END: Add a line to the purchase order
// -----
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();
});
It seems the key steps are as follows.
Record.selectNewLine()
to start constructing a new line.Record.setCurrentSublistValue()
to populate fields on the new line.Record.commitLine()
when you are done populating fields.The key parts of this solution were pulled from another answer. Just giving credit where credit is due. 🙂
Upvotes: 0
Reputation: 937
The defaultValue object only accept entity
value. Please look at the record.create defaultValue
docs.
To Add your shipment item, you can do that by adding any other item to the item
sublist.
var purchaseOrderRecordObj = record.create({
type: record.Type.PURCHASE_ORDER,
isDynamic: true,
defaultValues: {
entity: 322
}
});
purchaseOrderRecordObj.setValue({ fieldId: 'createdfrom', value: 4427821, ignoreFieldChange: false }); //createdfrom no soid
purchaseOrderRecordObj.setValue({ fieldId: 'subsidiary', value: 9, ignoreFieldChange: false });
purchaseOrderRecordObj.setValue({ fieldId: 'memo', value: "Created from Sales Order as Dropship", ignoreFieldChange: false });
purchaseOrderRecordObj.setValue({ fieldId: 'employee', value: 3, ignoreFieldChange: false });
purchaseOrderRecordObj.selectNewLine({ sublistId: 'item' });
purchaseOrderRecordObj.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: '<DROP_SHIP_ITEM_ID', ignoreFieldChange: false })
//if you want to change the quantity, or the price do here ...
purchaseOrderRecordObj.commitLine({ sublistId: 'item', ignoreRecalc: false })
purchaseOrderRecordObj.save({ ignoreMandatoryFields: true });
Hope This helps.
Upvotes: 1