Nicholas Williams
10/07/2021, 8:47 PMbarinvon
10/07/2021, 10:16 PMNick
10/07/2021, 11:51 PMbarinvon
10/08/2021, 12:27 AMNicholas Williams
10/08/2021, 1:03 AM/**
*@NApiVersion 2.0
*@NScriptType ClientScript
*/
define(['N/ui/dialog', 'N/search', 'N/currentRecord'],
function (dialog, search, curRec) {
function pageInit(scriptContext) {
}
/**
*
* @param scriptContext
* @param scriptContext.currentRecord
* @param scriptContext.sublistId
* @param scriptContext.fieldId
* @param scriptContext.line
*/
function fieldChanged(scriptContext) {
if (scriptContext.sublistId === 'item' || scriptContext.sublistId === 'expense' && scriptContext.fieldId === 'custcol_psc_location_line') {
scriptContext.currentRecord.selectLine({
sublistId: 'item',
line: scriptContext.line
});
var pscLocationLine = scriptContext.currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_psc_location_line'
});
var locationName = '';
if (pscLocationLine) {
locationName = search.lookupFields({
type: 'customrecord_psc_cc_loc_combos',
id: pscLocationLine,
columns: 'custrecord_psc_cclc_location'
});
}
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'location',
value: locationName ? locationName.custrecord_psc_cclc_location[0].value : '',
ignoreFieldChange: true
});
}
}
/**
*
* @param scriptContext
* @param scriptContext.currentRecord
* @param scriptContext.sublistId
*/
function lineInit(scriptContext) {
var myRecord = curRec.get();
var pscCostCenter = myRecord.getValue({
fieldId: 'department'
});
var location = myRecord.getValue({
fieldId: 'custbody_psc_location'
});
if (scriptContext.sublistId == 'item' || scriptContext.sublistId == 'expense') {
if (pscCostCenter) {
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: scriptContext.sublistId,
fieldId: 'department',
value: pscCostCenter,
ignoreFieldChange: false,
});
}
if (location) {
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: scriptContext.sublistId,
fieldId: 'custcol_psc_location_line',
value: location,
ignoreFieldChange: false,
});
}
}
}
/**
*
* @param scriptContext
* @param scriptContext.currentRecord
* @param scriptContext.sublistId
* @param scriptContext.fieldId
*/
function postSourcing(scriptContext) {
}
function saveRecord(scriptContext) {
}
function sublistChanged(scriptContext) {
}
function validateDelete(scriptContext) {
}
function validateField(scriptContext) {
}
function validateInsert(scriptContext) {
}
return {
// pageInit: pageInit,
fieldChanged: fieldChanged,
lineInit: lineInit,
// postSourcing: postSourcing,
// saveRecord: saveRecord,
// sublistChanged: sublistChanged,
// validateDelete: validateDelete,
// validateField: validateField,
// validateInsert: validateInsert
};
});
Nicholas Williams
10/08/2021, 1:04 AMbarinvon
10/08/2021, 1:13 AMmyRecord = scriptContext.currentRecord;
instead of curRec.get() and I like to put a console log in pageInit and use browser developer tools to open script and debug, see if you are getting those valuesNicholas Williams
10/08/2021, 1:21 AMNicholas Williams
10/08/2021, 1:21 AMvar myRecord = scriptContext.currentRecord;
var pscCostCenter = myRecord.getValue({
fieldId: 'department'
});
var location = myRecord.getValue({
fieldId: 'custbody_psc_location'
});
console.log(pscCostCenter)
barinvon
10/08/2021, 2:01 AMNicholas Williams
10/08/2021, 2:06 AMbattk
10/08/2021, 2:30 AMNicholas Williams
10/08/2021, 2:38 AMNicholas Williams
10/08/2021, 2:38 AM/**
*@NApiVersion 2.0
*@NScriptType ClientScript
*/
define(['N/ui/dialog', 'N/search', 'N/currentRecord'],
function (dialog, search, curRec) {
function pageInit(scriptContext) {
}
/**
*
* @param scriptContext
* @param scriptContext.currentRecord
* @param scriptContext.sublistId
* @param scriptContext.fieldId
* @param scriptContext.line
*/
function fieldChanged(scriptContext) {
if (scriptContext.fieldId == 'item') {
var myRecord = scriptContext.currentRecord;
var pscCostCenter = myRecord.getValue({
fieldId: 'department'
});
var location = myRecord.getValue({
fieldId: 'custbody_psc_location'
});
if (pscCostCenter) {
myRecord.setCurrentSublistValue({
sublistId: scriptContext.sublistId,
fieldId: 'department',
value: pscCostCenter,
ignoreFieldChange: true,
});
}
if (location) {
myRecord.setCurrentSublistValue({
sublistId: scriptContext.sublistId,
fieldId: 'custcol_psc_location_line',
value: location,
ignoreFieldChange: true,
});
}
}
// if (scriptContext.fieldId === 'custcol_psc_location_line') {
// scriptContext.currentRecord.selectLine({
// sublistId: 'item',
// line: scriptContext.line
// });
// var pscLocationLine = scriptContext.currentRecord.getCurrentSublistValue({
// sublistId: 'item',
// fieldId: 'custcol_psc_location_line'
// });
// var locationName = '';
// if (pscLocationLine) {
// locationName = search.lookupFields({
// type: 'customrecord_psc_cc_loc_combos',
// id: pscLocationLine,
// columns: 'custrecord_psc_cclc_location'
// });
// }
// scriptContext.currentRecord.setCurrentSublistValue({
// sublistId: 'item',
// fieldId: 'location',
// value: locationName ? locationName.custrecord_psc_cclc_location[0].value : '',
// ignoreFieldChange: true
// });
// }
}
/**
*
* @param scriptContext
* @param scriptContext.currentRecord
* @param scriptContext.sublistId
*/
function lineInit(scriptContext) {
var myRecord = scriptContext.currentRecord;
var pscCostCenter = myRecord.getValue({
fieldId: 'department'
});
var location = myRecord.getValue({
fieldId: 'custbody_psc_location'
});
if (pscCostCenter) {
myRecord.setCurrentSublistValue({
sublistId: scriptContext.sublistId,
fieldId: 'department',
value: pscCostCenter,
ignoreFieldChange: true,
});
}
if (location) {
myRecord.setCurrentSublistValue({
sublistId: scriptContext.sublistId,
fieldId: 'custcol_psc_location_line',
value: location,
ignoreFieldChange: true,
});
}
}
/**
*
* @param scriptContext
* @param scriptContext.currentRecord
* @param scriptContext.sublistId
* @param scriptContext.fieldId
*/
function postSourcing(scriptContext) {
}
function saveRecord(scriptContext) {
}
function sublistChanged(scriptContext) {
}
function validateDelete(scriptContext) {
}
function validateField(scriptContext) {
}
function validateInsert(scriptContext) {
}
return {
//pageInit: pageInit,
fieldChanged: fieldChanged,
lineInit: lineInit,
// postSourcing: postSourcing,
// saveRecord: saveRecord,
// sublistChanged: sublistChanged,
// validateDelete: validateDelete,
// validateField: validateField,
// validateInsert: validateInsert
};
});
Nicholas Williams
10/08/2021, 2:38 AMbattk
10/08/2021, 2:42 AMbattk
10/08/2021, 2:43 AMbattk
10/08/2021, 2:44 AMbattk
10/08/2021, 2:44 AMNicholas Williams
10/08/2021, 2:44 AMbattk
10/08/2021, 2:44 AMbattk
10/08/2021, 2:45 AMNicholas Williams
10/08/2021, 2:45 AMNicholas Williams
10/08/2021, 2:45 AMNicholas Williams
10/08/2021, 2:45 AMbattk
10/08/2021, 2:46 AMbattk
10/08/2021, 2:46 AMNicholas Williams
10/08/2021, 2:47 AMNicholas Williams
10/08/2021, 2:47 AMbattk
10/08/2021, 2:49 AMbattk
10/08/2021, 2:49 AMNicholas Williams
10/08/2021, 2:49 AMbattk
10/08/2021, 2:50 AMbattk
10/08/2021, 2:50 AMNick
10/08/2021, 2:53 AM