I’m trying to automate linking the NetSuite purchase order to a NetSuite sale order and the following is the code I tried to accomplish this task. But I'm getting error (see at the bottom). Can you please check and let me know what I’m missing here?
Purchase Order Creation code:
var createPurchaseOrder = new PurchaseOrder();
createPurchaseOrder.entity = new RecordRef()
{
internalId = “653”
//type = RecordType.purchaseOrder,
//typeSpecified = true
};
RecordRef soRecordRef = new RecordRef();
soRecordRef.internalId = “XXXXXXXX”;
soRecordRef.type = RecordType.salesOrder;
soRecordRef.typeSpecified = true;
createPurchaseOrder.createdFrom = soRecordRef;
RecordRef depRecordRef = new RecordRef();
depRecordRef.internalId = “3”;
depRecordRef.name = “eBay : eBay FNC”;
depRecordRef.type = RecordType.department;
depRecordRef.typeSpecified = true;
createPurchaseOrder.department = depRecordRef;
PurchaseOrderItem[] Items = new PurchaseOrderItem[1];
Items[0] = new PurchaseOrderItem();
RecordRef item = new RecordRef();
item.type = RecordType.nonInventoryPurchaseItem;
item.typeSpecified = true;
item.internalId = “XXXXX”;
Items[0].item = item;
Items[0].rate = “5”;
Items[0].quantity = 1;
Items[0].quantitySpecified = true;
PurchaseOrderItemList purchaseOrderItemList = new PurchaseOrderItemList();
purchaseOrderItemList.item = Items;
createPurchaseOrder.itemList = purchaseOrderItemList;
WriteResponse response = Service.add(createPurchaseOrder);
Code I'm using to Update Purchase Order Number in Sales Order:
var updateSalesOrder = new SalesOrder();
updateSalesOrder.internalId = “XXXXXXXX”;
SalesOrderItem[] soItems = new SalesOrderItem[1];
var soItem = new SalesOrderItem();
RecordRef roItem = new RecordRef();
roItem.type = RecordType.inventoryItem;
roItem.typeSpecified = true;
roItem.internalId = “XXXXX”;
soItem.item = roItem;
RecordRef prLevel = new RecordRef();
prLevel.type = RecordType.priceLevel;
prLevel.internalId = “-1”;
prLevel.typeSpecified = true;
soItem.price = prLevel;
soItem.rate = “15”;
soItem.quantity = 1;
soItem.quantitySpecified = true;
RecordRef poItem = new RecordRef();
poItem.type = RecordType.purchaseOrder;
poItem.typeSpecified = true;
poItem.internalId = purchaseOrder.internalId;
soItem.createdPo = poItem;
soItems[0] = soItem;
SalesOrderItemList salesOrderItemList = new SalesOrderItemList();
salesOrderItemList.item = soItems;
updateSalesOrder.itemList = salesOrderItemList;
response = Service.update(updateSalesOrder);
if (response.status.isSuccess != true) throw new Exception(response.status.statusDetail[0].message);
But I get the follwoing Error: You do not have permissions to set a value for element createPOSpecified due to one of the following reasons: 1) The field is read-only; 2) An associated feature is disabled; 3) The field is available either when a record is created or updated, but not in both cases.
Note: createPOSpecified is not displayed in the sales order screen in NetSuite. When I try to update a field in the sales order which exist in the form, then I am able to update it successfully but the field I am trying to update (createPOSpecified ) is not available in this sales form. In this case how can I update this ? Also is this the better way of linking the purchase order with sales order?
Thanks, Hemant.
Updated 25-May-2020 (Responding to Anand Rajaram)
We are using the ADMINISTRATOR role for creating purchase order and linking that to sales order. A user with this role has been provided by our client and we don’t have permission to see fields that are displayed in the screen and have been restricted for EDIT. But we are able to edit most of the field displayed in the screen.
createPOSpecified is not a custom field. It’s a property in the SALESORDETITEM class. It will not be displayed in any sales order form.
If this is the proper code for creating purchase order and linking that to sales order, then I have few queries:
3.1 When we create purchase order through NetSuite by clicking the dropship link in the sales order item grid, we are able to see Mark Shipped button.
But when we create purchase order through code, it is displaying the Receive button and there was no changes in the purchase order status.
3.2 **createdFrom** field is displaying as below when we create purchase order through netsuite.
This field is not displaying when we are creating purchase order through code. We have provided information for createdFrom property, but not sure why it is not displaying
We assume this is the field that helps to link with sales order. We have provided this information while creating item fulfillment and vendor bill and these are properly linked with sales order, but we are not sure why purchase order is not getting linked with sales order.
We don’t have any custom transaction body field in our sales order form for providing purchase order. But once purchase order is created through NetSuite, purchase order number will be displayed in the sales order item grid.
So all this boils down to: what is that we have missed in the code and what is that we have to fix to display the "Mark Shipped" button, “Created From" label and linking Purchase Order to Sales Order.
Thanks, Hemant.
Only sales orders for the same customer can be merged.
To close a purchase order:Go to Transactions > Purchases/Vendors > Enter Purchase Orders > List. Click View next to the purchase order you want to close. Click the Close button. This closes all line items on the purchase order.
I don't have an answer, but hopefully I can contribute. First of all, I think you're approaching this from the wrong direction. Rather than creating the PO and then trying to link it to the SO, I think you'll have to initialize the PO via the native dropship process and then save the PO. For example, creating a drop ship PO is pretty easy in SuiteScript 2.0. Here's how it's done:
var purchaseOrder = record.create ({
type: record.Type.PURCHASE_ORDER,
isDynamic: true,
defaultValues: {
recordmode: 'dynamic',
soid: '11111',
dropship: true,
custid: '22222',
entity: '33333'
}
})
This new PO is populated with all valid items from the SO and when it's saved all the linking is done automatically (createdFrom
is automatically set on the PO; createdPo
is automatically set on the SO item). I tried to recreate this in SuiteTalk using two different methods, both of which failed. Here they are:
The first approach tries to emulate the SuiteScript method using the initialize()
method. This is how you create an SO from an Estimate, or an IF from an SO, so it seems promising:
var initrec = new InitializeRecord
{
type = InitializeType.purchaseOrder,
reference = new InitializeRef
{
internalId = "11111",
type = InitializeRefType.salesOrder,
typeSpecified = true
}
};
var res = NSBase.Client.Service.initialize(initrec);
// "You can not initialize purchaseOrder by referencing salesOrder."
The error is self-explanatory. It's not possible to create a PO from an SO using initialize()
. This is very disheartening.
The second approach essentially tries to programmatically click the "drop ship" link on the line item. It fails with a similar error to the one you encountered before:
var objSO = new SalesOrder();
objSO.internalId = "11111";
objSO.itemList = new SalesOrderItemList
{
item = new SalesOrderItem[]
{
new SalesOrderItem { line = 10, lineSpecified = true, createPo = SalesOrderItemCreatePo._dropShipment, createPoSpecified = true }
},
replaceAll = false
};
var result = Service.update(objSO);
// "You do not have permissions to set a value for element item.createpo due to one of the following reasons: 1) The field is read-only; 2) An associated feature is disabled; 3) The field is available either when a record is created or updated, but not in both cases."
Unfortunately, this is the best I can do. The initialization approach definitely seems like the most likely solution to the problem, and the fact that it fails makes me wonder if it is even possible to create a drop ship/special order PO using SuiteTalk.
As an addendum to Will C.'s outstanding answer, there are three undocumented fields that you can use in suitescript to associate a purchase order line with a sales order line.
These fields are:
createdfrom
-- this should be set to the internalid
of the salesorder
orderdoc
-- this should be set to the internalid
of the salesorder
orderline
-- this should be set to the 1-indexed line id of the sales order item that you want to link to the purchase orderid
-- this should be set to the concatenation of orderdoc
and orderline
separated by an _
(underscore).these four fields allow you to associate any arbitrary purchase order line with a sales order line even if those lines were not pulled into the purchase order from the call to record.create
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With