- When adding a new line item, check the first occurrence of that item in the ‘validateField’ entry point. (This will return the index of the first occurrence of that item)
- Then check the index of the current line item.
- If the indexes are different, then we can assume that the selected item is already been added. So, return true to restrict the entry.
- If the value of the first occurrence is -1 then, the item is new, so it will allow you to add the item.
FIRST_OCCURENCE = currentRecord.findSublistLineWithValue({
sublistId: 'item',
fieldId: 'item',
value: newItem
});
let currentLineIndex = currentRecord.getCurrentSublistIndex({
sublistId: 'item'
});
if ((FIRST_OCCURENCE != currentLineIndex) && (FIRST_OCCURENCE != -1)) {
alert('This SKU/item has already been added once. Please try adding a different Item');
return false;
} else {
return true;
}