How to restrict the multiple entry of the same item in the sales order

  1. 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)
  2. Then check the index of the current line item.
  3. If the indexes are different, then we can assume that the selected item is already been added. So, return true to restrict the entry.
  4. 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;
                                }

Leave a comment

Your email address will not be published. Required fields are marked *