Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netsuite: How to link Purchase Order to Sales Order

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)

  1. 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.

  2. createPOSpecified is not a custom field. It’s a property in the SALESORDETITEM class. It will not be displayed in any sales order form.

enter image description here

  1. 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.

enter image description here

But when we create purchase order through code, it is displaying the Receive button and there was no changes in the purchase order status.

enter image description here

3.2 **createdFrom** field is displaying as below when we create purchase order through netsuite.

enter image description here

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

enter image description here

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.

  1. Finally on the below comments which you have provided Which is basically having a custom transaction body field on Sales Order form, and once PO is created, update the newly created PO in Sales Order field.

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.

enter image description here

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.

like image 576
Hemant Avatar asked May 21 '20 14:05

Hemant


People also ask

Can you merge sales orders in NetSuite?

Only sales orders for the same customer can be merged.

How do I Unclose a purchase order in NetSuite?

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.


2 Answers

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.

like image 70
Will Charbonneau Avatar answered Nov 10 '22 01:11

Will Charbonneau


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 order
  • id -- 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.

like image 21
2ps Avatar answered Nov 10 '22 00:11

2ps