Write a script to generate Intercompany Sales Orde...
# ask-stanley-ai
p
Write a script to generate Intercompany Sales Order with an Inventory Item.
c
AI generated answer (using internal Slack threads):
To generate an Intercompany Sales Order with an Inventory Item via SuiteScript, you can use the
N/record
module to create a new Sales Order record and set the necessary fields. Here's a simplified example:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/record'], function(record) {
    function onRequest(context) {
        try {
            var salesOrder = record.create({
                type: record.Type.SALES_ORDER,
                isDynamic: true
            });

            salesOrder.setValue({
                fieldId: 'entity',
                value: 'internalIdOfCustomer'
            });

            salesOrder.setValue({
                fieldId: 'subsidiary',
                value: 'internalIdOfSubsidiary'
            });

            salesOrder.selectNewLine({
                sublistId: 'item'
            });

            salesOrder.setCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'item',
                value: 'internalIdOfInventoryItem'
            });

            salesOrder.setCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'quantity',
                value: 1
            });

            salesOrder.commitLine({
                sublistId: 'item'
            });

            var salesOrderId = salesOrder.save();

            log.debug('Sales Order ID: ' + salesOrderId);
        } catch (e) {
            log.error(e.name, e.message);
        }
    }

    return {
        onRequest: onRequest
    };
});
This script creates a new Sales Order, sets the customer and subsidiary, adds an Inventory Item to the line items, and saves the record. Replace
'internalIdOfCustomer'
,
'internalIdOfSubsidiary'
, and
'internalIdOfInventoryItem'
with the actual internal IDs of the customer, subsidiary, and inventory item. Please note that this is a simplified example and you might need to set more fields depending on your specific requirements and NetSuite setup. ****** 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.84463352
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.844341338
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.84393543
Please provide your feedback on this answer.