Search code examples
netsuitesuitescript

NetSuite - Multiple Subsidiaris for Vendor Import Issue


looks like there is a limitation when we mass import Vendors into NetSuite in that we cannot specify multiple subsidiaries in our mappings.

Since I need to import few 100 vendors I don't really wish to edit each vendor record where a vendor requires more than on subsidiary.

Are we able to do anything clever in code for this or has anyone got a solution for this limitation?

Thanks


Solution

  • As an alternative to Rusty Shackles, there's an undocumented sublist that is accessible on vendor records for the subsidiaries. This sublist has the name submachine. For whatever reason, it must be accessed using record.selectLineItem,record.setCurrentLineItemValue, and record.commitLineItem as opposed to the record.setLineItemValue API functions.

    For example, I have a mass update script that was used to replace a subsidiary from every vendor on the mass update search. Here's the code sample

    function massUpdate(recType, recId) {
        var context = nlapiGetContext();
        var subToRemove = context.getSetting('SCRIPT', 'custscript_subsidiary_to_remove');
        var subToReplace = context.getSetting('SCRIPT', 'custscript_replacement_sub');
        var record = nlapiLoadRecord('vendor', recId);
        var lineCount = record.getLineItemCount('submachine');
        nlapiLogExecution('DEBUG', 'lineCount = ' + lineCount)
        if (lineCount > 0){
            for (var i = 1; i <= lineCount; i++){
                record.selectLineItem('submachine', i);
                var sub = record.getCurrentLineItemValue('submachine', 'subsidiary')
                nlapiLogExecution('DEBUG', i, sub);
                if (sub == subToRemove){
                    record.setCurrentLineItemValue('submachine', 'subsidiary', subToReplace);
                    record.commitLineItem('submachine');
                    break;
                }
            }
        }
        nlapiSubmitRecord(record);
    }
    

    So that opens up the possibility of writing your own scheduled script that processes a file and updates the subsidiary list, for whatever reason a CSV upload isn't useable.