OnCell Edit Start date and End Date validation For Date field modification in List View.

Dinesh Kumar11
Kilo Sage
Kilo Sage

I am Modifying data to date fields in list view, i need validation on list view editing start date is Less then End date and end date is Greater then start date. i am able to do form edit on date fields change but i need to apply same thing in list edit also. please help with solution.

 

Thanks in advance. 

 

 

Thanks & Regards

RDK

1 ACCEPTED SOLUTION

Hello Harshal ,

 

Thanks for your reply,

 

I am able to do with before update Business rule.

 

(function executeRule(current, previous /*null when async*/ ) {

if ((!current.startdate.nil()) && (!current.enddate.nil())) {
var start = (new GlideDateTime(current.getValue('startdate'))).getNumericValue();
var end = (new GlideDateTime(current.getValue('enddate'))).getNumericValue();
if (start > end) {
gs.addInfoMessage('End Date should be greater than start date');
current.startdate.setError('End Date should be greater than start date');
current.setAbortAction(true);
}
}

})(current, previous);

 

Thanks Again.

 

Remember to mark any post/answer/comment as being either correct or helpful.

 

Regards,

RDK.

View solution in original post

3 REPLIES 3

Harshal Gawali
Giga Guru

Hi Dinesh,

 

g_user_date_format is a global variable that gives you the user's date format.

formatDate and getDateFromFormat are two useful functions for working with dates on the client.

Please check below script It will help you for Date Validation on List view.

 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {

var saveAndClose = true;

 

  //current date  

 

  var currentDateObj = new Date();  

 

  var currentDateStr = formatDate(currentDateObj, g_user_date_format);  

 

  var currentDateNum = getDateFromFormat(currentDateStr, g_user_date_format);  

 

 

 

  var startDateNum = getDateFromFormat(newValue, g_user_date_format);  

 

                 

 

      if (startDateNum <= currentDateNum) {  

 

      g_form.showFieldMsg('Please ensure that the Expiry date is in the future!', 'error');

 

  return false;

 

  }

 

callback(saveAndClose);
}

 

 

Regards,

Harshal Gawali.

Hello Harshal ,

 

Thanks for your response.

 

It's not working for my scenario, please review the below code. 

endDate is value of End date ....

start date is newValue...

 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {

var saveAndClose = true;

//current date

var currentDateObj = new Date();
var endDate = g_form.getValue('enddate');



var currentDateStr = formatDate(currentDateObj, g_user_date_format);
var currentDateNum = getDateFromFormat(endDate, g_user_date_format);
var startDateNum = getDateFromFormat(newValue, g_user_date_format);

if (startDateNum <= endDate) {

g_form.showFieldMsg('Please ensure that the Expiry date is in the future!', 'error');


return false;

}

callback(saveAndClose);
}

 

 

please review and help me with this. 

 

Thanks in advance.

Hello Harshal ,

 

Thanks for your reply,

 

I am able to do with before update Business rule.

 

(function executeRule(current, previous /*null when async*/ ) {

if ((!current.startdate.nil()) && (!current.enddate.nil())) {
var start = (new GlideDateTime(current.getValue('startdate'))).getNumericValue();
var end = (new GlideDateTime(current.getValue('enddate'))).getNumericValue();
if (start > end) {
gs.addInfoMessage('End Date should be greater than start date');
current.startdate.setError('End Date should be greater than start date');
current.setAbortAction(true);
}
}

})(current, previous);

 

Thanks Again.

 

Remember to mark any post/answer/comment as being either correct or helpful.

 

Regards,

RDK.