why is the field subsidiarylocation mandatory on v...
# ask-stanley-ai
p
why is the field subsidiarylocation mandatory on vendor return authorizations if you have cross-subsidiary fulfillment enabled?
c
AI generated answer (using internal Slack threads):
The field 'subsidiarylocation' is mandatory on vendor return authorizations when you have cross-subsidiary fulfillment enabled because of the way NetSuite handles inventory and cost centers. When cross-subsidiary fulfillment is enabled, the inventory location is no longer determined at the body level, but at the line level. This means that for each item in the order, you need to specify the inventory location. This is particularly important when you have multiple subsidiaries and locations, as it allows you to specify exactly where the inventory for each item is coming from. The 'subsidiarylocation' field is crucial in this process because it determines the cost center for the transaction. In other words, it specifies which subsidiary is financially responsible for the inventory. This is important for accurate financial reporting and for maintaining the correct inventory levels at each location. Here is a sample script that was shared in the thread, which automatically sets the line level inventory location based on the header location:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/error', 'N/log', 'N/record','N/runtime'],
function(error, log, record,runtime) {
    const LINE_FIELD_INVENTORY_LOCATION = 'inventorylocation';
    function soBeforeSubmit(scriptContext){
        if(scriptContext.type == scriptContext.UserEventType.CREATE || scriptContext.type == scriptContext.UserEventType.EDIT){
            try{
                var headerLocation = scriptContext.newRecord.getValue({
                    fieldId: 'location'
                });
                var transactionSubsdiary = scriptContext.newRecord.getValue({
                    fieldId: 'subsidiary'
                });
                log.debug('transactionSubsdiary'+transactionSubsdiary);              
                //If the subsidiary is  do this, otherwise do not execute.
                if(transactionSubsdiary == 6 || transactionSubsdiary == 7 ){ 
                    //get the number if line is on the Sales Order
                    if (headerLocation){
                        var itemcount = scriptContext.newRecord.getLineCount({
                            sublistId: 'item'
                        });
                        log.debug('transactionSubsidiary:'+transactionSubsdiary+' Location ID:'+headerLocation+' No of lines:'+itemcount);
                        //get the existing line inventory location
                        for(var i = 0; i < itemcount; i++){
                            var lineLocation = scriptContext.newRecord.getSublistValue({
                                sublistId: 'item',
                                fieldId: LINE_FIELD_INVENTORY_LOCATION,
                                line: i
                            });
                            //update the line INventory Location if it does not match the header location.		
                            if(lineLocation != headerLocation){
                                scriptContext.newRecord.setSublistValue({
                                    sublistId: 'item',
                                    fieldId: LINE_FIELD_INVENTORY_LOCATION,
                                    line: i,
                                    value: headerLocation
                                });
                            }
                        }
                    }
                }
            }
            catch(e){
                log.debug(e.name,e.message);
            }
        }
    }
    return {
        beforeSubmit: soBeforeSubmit
    };
});
****** 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.83534658
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827932537
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.820425272
Please provide your feedback on this answer.
p
can you set subsidiarylocation via csv import?
r
The bot isn't yet programmed to respond to questions in-line. But you can continue asking in the main channel