Hello Gurus,
I am having abit of a challenge with a client script i made to make the class field on the vendor bill mandatory when users are raising expense bills. The validation works perfectly if the vendor bill has only one line. However, if the bill has more than one line, the validation doesn't work on the subsequent lines. Below is the script:
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord'],
function(currRec) {
function saveRecord(scriptContext) {
var rec = scriptContext.currentRecord;
var lineCount = rec.getLineCount({
sublistId: 'expense'
});
for (var i = 0; i <= lineCount; i++) {
var objField = rec.getSublistValue({
sublistId: 'expense',
fieldId: 'class',
line: i
});
log.debug(objField)
if(!objField){
alert('Please update the class');
return false;
}else{
return true;
}
}}
return {
saveRecord: saveRecord
};
});
I am still learning my way around scripting but i have managed to work out that the issue could be because of the condition on the line variable(var i = 0). If i try to change that to var (>=) 0 then i get an error (Syntax error: missing ; after for-loop). I would appreciate any help i can get to get around this?.
I cannot use the global company setting to make the class mandatory as class is only required on the line level when raising the bills.
Thanks