Restricting The Use Of Discount Item From a Particular Date

The client needs to restrict their people from selecting the discount item from the transaction after June 6th

 function compareDates(d1, d2){
            var date1 = new Date(d1).getTime();
            var date2 = new Date(d2).getTime();
          
            if (date1 > date2) {
              return true
            } 
            return false;
          }

In pageInt we will take the trandate date pass it to the function and stored in a global variable.

var date=recordObj.getValue({fieldId: 'trandate'});
date=generateDateString(date);
discountAllowed=compareDates(date,"6/06/2023")

In validateLine we will check whether it is a discount Item 

  if (sublistName === 'item') {
                    var lineItem = currentRec.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'item'
                    });
                    console.log("lineItem", lineItem)
                    var amount = currentRec.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'amount'
                    });
                    
                    var itemType=currentRec.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'itemtype'
                    });
                    console.log("itemType",itemType)
                    if(itemType=="Discount" && (discountAllowed || discountAllowed== true)){
                        alert("You Have No permission To Add Discount Items From June 6,2023")
                        return false;
                    }
}

Leave a comment

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