I want to view record type which is selected on entity column in journal sublist?
I create a custom field and deploy a script. Here is my script and don’t know whats wrong in it.
/**
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define([‘N/ui/dialog’,’N/record’,’N/log’],
function(dialog,record,log) {
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var sublistid = context.sublistId;
if(fieldChanged.fieldId ==’entity’){
var name = currentRecord.getCurrentSublistValue({
sublistId: ‘line’,
fieldId: ‘entity’
});
// dialog.alert({
// title:’name:’,
// message: name
// })
if(name==record.Type.EMPLOYEE){
currentRecord.setCurrentSublistValue({
sublistId:’line’,
fieldId:’custcol_ks_recordtype’,
value:’Employee’
});
console.log(name)
}
if(name==record.Type.CUSTOMER){
currentRecord.setCurrentSublistValue({
sublistId:’line’,
fieldId:’custcol_ks_recordtype’,
value:’Customer’
});
}
if(name==record.Type.VENDOR){
currentRecord.setCurrentSublistValue({
sublistId:’line’,
fieldId:’custcol_ks_recordtype’,
value:’Vendor’
});
}
dialog.alert({
title:’name:’,
message: name
})
}
}
return {
fieldChanged: fieldChanged
}
});
Maybe Im wrong, but I think you always have to use the pageInit function… Try to include it
/**
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define([‘N/ui/dialog’,’N/record’,’N/log’],
function(dialog,record,log) {
function pageInit(context) {
//nothing to do
}
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var sublistid = context.sublistId;
if(fieldChanged.fieldId ==’entity’){
var name = currentRecord.getCurrentSublistValue({
sublistId: ‘line’,
fieldId: ‘entity’
});
// dialog.alert({
// title:’name:’,
// message: name
// })
if(name==record.Type.EMPLOYEE){
currentRecord.setCurrentSublistValue({
sublistId:’line’,
fieldId:’custcol_ks_recordtype’,
value:’Employee’
});
console.log(name)
}
if(name==record.Type.CUSTOMER){
currentRecord.setCurrentSublistValue({
sublistId:’line’,
fieldId:’custcol_ks_recordtype’,
value:’Customer’
});
}
if(name==record.Type.VENDOR){
currentRecord.setCurrentSublistValue({
sublistId:’line’,
fieldId:’custcol_ks_recordtype’,
value:’Vendor’
});
}
dialog.alert({
title:’name:’,
message: name
})
}
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged
}
});