Solution for making the Expiry Date field as a mandatory.

As we cannot set the field ‘Expiration Date’ mandatory via the NetSuite UI, we can use a User Event script as an alternative.

This script can be deployed in two records, such as item receipt and inventory adjustment.

The following script is designed to prompt the user prior to saving a record if the ‘Expiration Date’ field is not filled in:

const beforeSubmit = (scriptContext) => {

      let newRec = scriptContext.newRecord;

      let itemCount, subRec;

      if (newRec.type == ‘itemreceipt’) {

        itemCount = newRec.getLineCount({

          sublistId: ‘item’

        })

      }

      else {

        itemCount = newRec.getLineCount({

          sublistId: ‘inventory’

        })

      }

      for (i = 0; i < itemCount; i++) {

        if (newRec.type == ‘itemreceipt’) {

          subRec = newRec.getSublistSubrecord({

            sublistId: ‘item’,

            fieldId: ‘inventorydetail’,

            line: i

          })

        }

        else {

          subRec = newRec.getSublistSubrecord({

            sublistId: ‘inventory’,

            fieldId: ‘inventorydetail’,

            line: i

          })

        }

        let inventoryAssignmentCount = subRec.getLineCount({ sublistId: ‘inventoryassignment’ })

        for (j = 0; j < inventoryAssignmentCount; j++) {

          let expirationDate = subRec.getSublistValue({

            sublistId: ‘inventoryassignment’,

            fieldId: ‘expirationdate’,

            line: j

          })

          if (expirationDate == ” || expirationDate == null)

            throw “Expiration Date is empty for Inventory Detail. Please add an expiry date in the Inventory detail.”;

        }

      }

    }

    return { beforeSubmit }

  });

Leave a comment

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