Shelby Owens
06/26/2025, 6:36 PMCeligo AI
06/26/2025, 6:37 PMAI generated answer (using internal Slack threads):****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** The line level location on Sales Orders can be set using a User Event script or a workflow. The script would grab the header location and the line level location, compare the two, and if they are different, it would set the line level location to the header level. Here is a sample User Event script that was shared in the conversations:
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('transactionSubsdiary:'+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
};
});
This script is set to run before the Sales Order is submitted. It checks if the Sales Order is being created or edited. If so, it gets the header location and the subsidiary of the transaction. If the subsidiary matches certain values (in this case, 6 or 7), it gets the number of lines on the Sales Order. For each line, it gets the existing line inventory location. If the line inventory location does not match the header location, it updates the line inventory location to match the header location.
Please note that this script is just a sample and may need to be adjusted to fit your specific needs.Celigo AI
06/26/2025, 6:37 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.853532195
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840549707
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.823700726
Celigo AI
06/26/2025, 6:37 PM