Hello! For a Journal Entry, is it possibly to crea...
# general
b
Hello! For a Journal Entry, is it possibly to create a workflow which will automatically fill in the line level "location" field depending on which line level "account" is chosen? If so, how does this work?
m
WF is not possible without scripting because the sublist line is not supported ( only sublist item )
b
Thanks @Marc do you know what type of script that would be?
m
User Event or Client script
y
You need to use a client script or user event script to take care of the location based on the JE account line.
b
Hi @yagyakumarnag do you think a client script like below would work? I have tested this but it is not working how I would expect.
"/** * @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 }; });
🤖 1
y
I will suggestion would be to use field sourcing function. Issue here is that getLoctionsBasedOnAccount return text value in array format so you need to changes it logic as below. if(locations && locations.length>0) currentRecord.setCurrentSublistText({ sublistId: sublistId, fieldId: fieldIdLoction, text: locations[0] }); }
🙌 1