Quest has anyone successfully created an intercomp...
# suitescript
t
Quest has anyone successfully created an intercompany Sales Order and associate it with the purchase order. The transactions are correct to be able to be made into intercompany transaction pair (appropriate currency, sub, vendors, item and qty)
Copy code
let objRecord = record.create({
                type: record.Type.SALES_ORDER,
                isDynamic: false
            });
            //{fieldId: 'intercostatus', value: '1'},
            //{fieldId: 'intercotransaction', value: '6148432'}
            let headerFields = [
                {fieldId: 'entity', value: 428},
                {fieldId: 'subsidiary', value: 14},
                {fieldId: 'orderstatus', value: 'B'},
                {fieldId: 'currency', value: '1'}
            ];
            headerFields.forEach(function (fieldItem) {
                objRecord.setValue({
                    fieldId: fieldItem.fieldId,
                    value: fieldItem.value
                });
            });

            let sublistFields = [
                {fieldId: 'item', sublistId: 'item', value: 549069, line: 0},
                {fieldId: 'quantity', sublistId: 'item', value: 150, line: 0},
                {fieldId: 'rate', sublistId: 'item', value: 7.04, line: 0},
            ];
            sublistFields.forEach(function (sublistFieldItem) {
                objRecord.setSublistValue({
                    sublistId: sublistFieldItem.sublistId,
                    fieldId: sublistFieldItem.fieldId,
                    value: sublistFieldItem.value,
                    line: sublistFieldItem.line
                });
            });
            headerFields = [
                {fieldId: 'intercostatus', value: '1'},
                {fieldId: 'intercotransaction', value: '6148432'}
            ];
            headerFields.forEach(function (fieldItem) {
                objRecord.setValue({
                    fieldId: fieldItem.fieldId,
                    value: fieldItem.value
                });
            });
            newRecordId = objRecord.save();
The error its producing is
Copy code
Invalid intercotransaction reference key 6148432.
When it is a valid intercompany PO that is in a pending state
m
Have you already tried creating the SO without setting the intercompany fields, and then testing setting those fields in the UI?
t
Yeap, tried that you get a "You must create a purchase order first to transfer intercompany inventory." suitescript error (I assume its an internal NS before save UE script)
happens in the UI or using the script without the fields set
it seems the only place you can do it in the UI is "Manage Intercompany Sales Orders" and generate them that way
m
I haven't tried intercompany transactions yet so hopefully someone else can chime in. But usually with invalid reference key errors, you need to get it working in UI first before you can try replicating with a script
t
@michoel thanks was putting it out here because I was hoping this the comment from theaccountingnerd01 isn't correct but I fear it might be https://www.reddit.com/r/Netsuite/comments/htm3y3/intercompany_sales_order_via_scripting/
104 Views