- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 06:01 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 10:20 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 06:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 07:06 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 10:20 AM
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.