"/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/log', 'N/record'],
function(log, record) {
function pageInit(context) {
// Add any page initialization logic here
}
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var sublistId = 'line';
var fieldIdAccount = 'account';
var fieldIdLocation = 'location';
if (context.fieldId === fieldIdAccount && context.sublistId === sublistId) {
var line = context.line;
var account = currentRecord.getCurrentSublistValue({
sublistId: sublistId,
fieldId: fieldIdAccount
});
// Filter locations based on account
var locations = getLocationsBasedOnAccount(account);
// Set the location field for the current line
currentRecord.setCurrentSublistValue({
sublistId: sublistId,
fieldId: fieldIdLocation,
value: locations
});
}
}
function getLocationsBasedOnAccount(account) {
// Add your custom logic to determine the location based on the account
// For simplicity, we'll return specific locations for account 612
if (account === '612') {
// Return the array of locations for account 612
return ['Nashville', 'Cleveland', 'Detroit'];
} else {
// Return default locations or handle other account scenarios
return [];
}
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged
};
});