Restrict a date field value in record producer.

Prasnajeet1
Giga Guru

HI All

I have requirement to restrict user to enter past date in the Delivery date field in a record producer. For this I have already a script include and that triggered from a BR. Now I want to call this script include using client script. Please help on the scripting part to call this script include using client script.

 

Script Include:

var TransferOrderDateTimeAjax = Class.create();

TransferOrderDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor , {

/*
* Compares two dates coming both from the client's timezone
*/
compareDatesAjax: function() {
var startDate = new GlideDateTime();
startDate.setDisplayValue(this.getParameter('sysparm_startDate'));
var endDate = new GlideDateTime();
endDate.setDisplayValue(this.getParameter('sysparm_endDate'));
return this.compareDates(endDate, startDate);
},

/*
* Compares two dates from the same timezone
*/
compareDates: function(/*GlideDateTime*/ date1, /*GlideDateTime*/ date2) {
var diff = gs.dateDiff(date1, date2, true);
return (diff <= 0);
},

/*
* Compares a date in the server's timezone to now in the server timezone too
*/
isDateBeforeNow: function(/*GlideDateTime*/ date) {
var now = new GlideDateTime();
now.setDisplayValue((new Date()).toString());
return this.compareDates(now, date);
},

type: 'TransferOrderDateTimeAjax'
});

 

BR which call this script include:

var timeComp = new TransferOrderDateTimeAjax();
if (timeComp.isDateBeforeNow(current.delivery_by_date)) {
gs.addErrorMessage(gs.getMessage('Choose a delivery date in the future'));
current.setAbortAction(true);
}

 

I want same error message should populate, when a user enter past date in the delivery date field and that script include should call from client script. Please help in the scripting part please.

1 ACCEPTED SOLUTION

is the delivery date a field or variable on the record producer form? You can create a UI Policy for this no complex script required example below

HarishKM_0-1691138184624.png

 

HarishKM_1-1691138200597.pngHarishKM_2-1691138213272.png

 

Regards
Harish

View solution in original post

5 REPLIES 5

Hi Thomas

 

Now whatever time I select, Past or future, I am getting the error message. For future date it should there shouldn't be any error message and it should allow me to submit the request.