I have created custom select type department field on a journal entry’s sublist through user event before load script. I am getting context.mode value as blank. Now I am getting departments using field lookup from account record’s department field which is multiselect type. I am trying to insert those departments into journal entries custom department field using client script validate field event. But its adding same options on all lines of custom department field. Also When I try to add account on new line,then I am getting an error as “”type”:”error.SuiteScriptError”,”name”:”SSS_INVALID_SUBLIST_OPERATION”,”message”:”CurrentRecord.getSublistField”,”id”:null,”stack”:[“SSS_INVALID_SUBLIST_OPERATION: CurrentRecord.getSublistField”,” at Object.createError [as nlapiCreateError]
/**
*@NApiVersion 2.1
*@NScriptType ClientScript
*/
define([‘N/record’, ‘N/search’, ‘N/ui/dialog’],
function (record, search, dialog) {
function validateField(context)
{
try{
var currRec = context.currentRecord;
var sublistName = context.sublistId;
log.debug(“sublistName”,sublistName);
var sublistFieldName = context.fieldId;
log.debug(“sublistFieldName”,sublistFieldName);
log.debug(“context–>”,context);
if (sublistName === ‘line’ && sublistFieldName === ‘account’)
{
alert(“validate field”);
//Get account Value
var accountid = currRec.getCurrentSublistValue({
sublistId:’line’,
fieldId:’account’
})
log.debug(“accountid”,accountid);
var currIndex = currRec.getCurrentSublistIndex({
sublistId: ‘line’
});
log.debug(“currIndex–>”,currIndex);
var objField = currRec.getSublistField({
sublistId: ‘line’,
fieldId: ‘custpage_department’,
line: currIndex
});
log.debug(“objField”,objField);
//objField.removeSelectOption({ value: null });
var fieldLookUp = search.lookupFields({
type: search.Type.ACCOUNT,
id: accountid,
columns: [‘custrecord_cp_account_restrict_dept’,’custrecord_cp_dept_selection’]
});
var restrict=fieldLookUp.custrecord_cp_account_restrict_dept;
log.debug(“restrict:”,restrict);
if(restrict==false)
{
objField.removeSelectOption({ value: null });
var restrictDept=fieldLookUp.custrecord_cp_dept_selection;
log.debug(“restrictDept:”,JSON.stringify(restrictDept));
if(restrictDept.length>0)
{
for(var j=0;j<restrictDept.length;j++)
{
log.debug(“restrictDept value—>”,restrictDept[j].value);
objField.insertSelectOption({
value : restrictDept[j].value,
text : restrictDept[j].text
});
}
}
}
}
if (sublistName === ‘line’ && sublistFieldName === ‘custpage_department’)
{
alert(“validate field2”);
//Get account Value
var customDepartment=currRec.getCurrentSublistValue({
sublistId: ‘line’,
fieldId: ‘custpage_department’,
});
log.debug(“customDepartment validatefield”,customDepartment);
currRec.setCurrentSublistValue({
sublistId: ‘line’,
fieldId: ‘department’,
value:customDepartment
});
}
}catch(e)
{
log.error(“Error occurred: “, e);
}
return true;
}
return {
validateField:validateField
};
});