I need to show the alert()
through my client script, when some conditions met. But I couldn't print the record numbers which would be key information to the user that these specific records are causing the system to show an alert.
I have made a for loop, in which I m pushing the values of the docNo
(record Ids) in an array named docNoArr
.
Then in another for loop, I am triggering an alert with the values I pushed in the docNoArr
array.
Can anyone suggest me a better way to optimize the code as its repeating itself. My Teacher says to DRY : Dont Repeat Yourself. But here im stuck like how not to repeat.
My Code:
var docNoArr = [];
/* 1st For Loop */
for (var e = 0; e < count; e++) {
isApplied = rec.getSublistValue({
sublistId: subid,
fieldId: reqid,
line: e
});
if (isApplied == true) {
rectype = rec.getSublistValue({
sublistId: subid,
fieldId: 'custpage_am_rectype',
line: e
});
if (rectype == 'qcs') {
var supplierFld = rec.getValue({ fieldId: 'custpage_am_vendor' });
var docNoFld = rec.getSublistValue({
sublistId: subid,
fieldId: 'custpage_am_docnum',
line: e
});
var recomdSupplier = rec.getSublistValue({
sublistId: subid,
fieldId: 'custpage_am_supplier',
line: e
})
if (recomdSupplier != supplierFld) {
docNoArr.push(docNoFld);
}
}
}
}
/* 2nd For Loop */
for (var ee = 0; ee < count; ee++) {
isApplied1 = rec.getSublistValue({
sublistId: subid,
fieldId: reqid,
line: ee
});
if (isApplied1 == true) {
rectype1 = rec.getSublistValue({
sublistId: subid,
fieldId: 'custpage_am_rectype',
line: ee
});
if (rectype1 == 'qcs') {
var supplierFld1 = rec.getValue({ fieldId: 'custpage_am_vendor' });
var recomdSupplier1 = rec.getSublistValue({
sublistId: subid,
fieldId: 'custpage_am_supplier',
line: ee
});
if (recomdSupplier1 != supplierFld1) {
alert('Vendor selected in not recommended in ' + docNoArr + ' \nPlease enter Correct Vendor!');
return false;
}
}
}
}