I’m transforming a Purchase Order to a Vendor Bill...
# ask-stanley-ai
t
I’m transforming a Purchase Order to a Vendor Bill using REST Web Services API. All inventory details are already configured on the PO. However, when I modify or add line items in the request, it prompts for inventory details again. Ideally, if they’re already configured, it shouldn’t require them.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like you're encountering an issue with the REST Web Services API when transforming a Purchase Order (PO) to a Vendor Bill and modifying or adding line items. This issue is likely due to the sequence of operations in your request. In the REST API, the sequence of operations can be crucial. It's suggested to submit the item first before the amount. This means you should place the
"item": {"id": 42"}
above
"amount": 42
in your request. This is because the REST Web Services API operates similarly to the NetSuite UI, where the order of operations matters. However, if you're trying to partially bill a PO, you might encounter an error message stating "The total inventory detail quantity must be 40." This error can occur even if the quantity on the line and inventory detail is 40. This is because the REST API expects the Item Receipt (IR) quantity to be modified first before the Vendor Bill. To resolve this, you can modify the IR quantity to match the Vendor Bill. This can be done by using a before submit event on the Vendor Bill. Here's a simplified example of how you might structure your code:
Copy code
javascript
var vendorBillRec = record.transform({
    fromType: record.Type.PURCHASE_ORDER,
    fromId: params.purchaseOrderId,
    toType: record.Type.VENDOR_BILL,
});

vendorBillRec.setValue({fieldId: 'tranid', value: params.vendorBillReferenceNumber});

var lines = vendorBillRec.getLineCount({sublistId: 'item'});

for (var i = 0; i < lines; i++) {
    var item = vendorBillRec.getSublistValue({sublistId: 'item', fieldId: 'item', line: i});
    vendorBillRec.setSublistValue({sublistId: 'item', fieldId: 'quantity', line: i, value: dataMap[key].qty});
    vendorBillRec.setSublistValue({sublistId: 'item', fieldId: 'rate', line: i, value: dataMap[key].rate});

    var inventoryDetail = vendorBillRec.getSublistSubrecord({
        sublistId: 'item',
        fieldId: 'inventorydetail',
        line: i
    });

    inventoryDetail.setSublistValue({
        sublistId: 'inventoryassignment',
        fieldId: 'quantity',
        line: 0,
        value: parseFloat(dataMap[key].qty)
    });
}

var vendorBillId = vendorBillRec.save({enableSourcing: true, ignoreMandatoryFields: true});
****** 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.840582669
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840186059
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827061713
Please provide your feedback on this answer.