I have a Purchase Order that has an item on it. I ...
# ask-stanley-ai
s
I have a Purchase Order that has an item on it. I then added the item to an existing sales order. How do I tie the PO to the item on the sales order? I don't want to use a custom field but want the link to display in the CREATE PO filed that is already on the line, like I hit the drop ship or special order links that are displaying there now. I also want to do it in suitescript. I have the Sales Order loaded, I am search and find the PO id, and set the the poid on the sublist for the item, but the CREATE PO still displays the drop ship / special order links and not the link to the PO. Can I actually set the field? I can get a value out, but the set doesn't seem to work.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you can't directly set the 'Create PO' field on the Sales Order line to link to an existing Purchase Order (PO) in NetSuite. This field is system controlled and is used to generate a new PO when the Sales Order is approved, it's not designed to link to an existing PO. However, you can create a workaround by using a custom transaction line field on the Sales Order. This field can be used to store the internal ID of the related PO. You can then use SuiteScript to set this custom field when the Sales Order is saved. Here's a basic example of how you might do this:
Copy code
javascript
var salesOrder = record.load({
    type: record.Type.SALES_ORDER,
    id: salesOrderId,
    isDynamic: true
});

var lineCount = salesOrder.getLineCount({sublistId: 'item'});

for (var i = 0; i < lineCount; i++) {
    var poId = salesOrder.getSublistValue({
        sublistId: 'item',
        fieldId: 'yourCustomFieldId', // replace with your custom field ID
        line: i
    });

    if (poId) {
        salesOrder.setSublistValue({
            sublistId: 'item',
            fieldId: 'yourCustomFieldId', // replace with your custom field ID
            line: i,
            value: poId
        });
    }
}

salesOrder.save();
This script loads the Sales Order, iterates over each line, and if the custom field has a value (the internal ID of the PO), it sets the custom field with that value. The Sales Order is then saved, storing the link to the PO. Remember to replace 'yourCustomFieldId' with the actual ID of your custom field. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.86315918
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.859680176
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.852294922
Please provide your feedback on this answer.