RE: Link Purchase Order to Sales Order C#


I’m trying to automate linking the purchase order to a sale order and the following is the code I tried to accomplish this task. But I face error. Can you please check and let me know what I’m missing here

Purchase Order Creation: 

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”; = “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);

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);

Error which i get:

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 in Advance.


arulmani_m Rookie Asked on May 20, 2020 in SuiteTalk.
Add Comment
1 Answers

A Purchase Order is linked to a Sales Order automatically when it is created from that Sales Order (in case of Special Order Item or DropShip Item). For other cases, you would want to create a Custom Select field and Populate it.

Hope it helps!

Thanks in Advance.

Beginner Answered on June 1, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.