- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 01:55 AM
I have two date fields, start date and end date.
I have written oncell edit client script like below:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
var strDate = g_form.getValue('start_date');
var endDate = g_form.getValue('end_date');
if (endDate < strDate) {
alert("st= " + strDate + ' ' + "end= " + endDate);
}
callback(saveAndClose);
}
But it is not working. It working fine on onchnge client script.
Any suggestions?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 10:47 PM - edited 02-23-2024 12:02 AM
You can add an alert in the client script like the below:
Please mark this response as correct or helpful if it assisted you with your question.
Best Regards,
Rutuja Khalate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 03:11 AM
Hi @Naga Ravindra R
Can you try the below script please?
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
var strDate = g_form.getValue('start_date');
var endDate = g_form.getValue('end_date');
if (endDate < strDate) {
alert("st= " + strDate + ' ' + "end= " + endDate);
saveAndClose = false;
}
callback(saveAndClose);
}
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 04:24 AM
g_form is not working on list view and values are alos not working. I tried below code:
Client script:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
var daAjax = new GlideAjax('x_diocg_service_al.IOC_SAM_Utils');
daAjax.addParam('sysparm_name', 'datevalidation');
daAjax.addParam('sysparm_sys_ids', sysIDs);
daAjax.addParam('sysparm_end_date', newValue);
daAjax.getXML(dateResult);
function dateResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == -1) {
alert('End date cannot be before Start date');
callback(false);
}
}
callback(saveAndClose);
}
script include function:
datevalidation: function() {
var sys_id = this.getParameter('sysparm_sys_ids');
var endDate = new GlideDateTime(this.getParameter('sysparm_end_date'));
var events = sys_id.split(',');
for (var i = 0; i < events.length; i++) {
var gr = new GlideRecord('x_diocg_service_al_event');
gr.addQuery('sys_id', events[i]);
gr.query();
if (gr.next()) {
var strDate = new GlideDateTime(gr.start_date);
var comp_date = endDate.compareTo(strDate);
if (comp_date == -1) {
return -1;
} else {
return 1;
}
}
}
Alert is working fine, but aborting the action is not working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 05:14 AM
Can you try with below oncelledit client script :
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
var daAjax = new GlideAjax('x_diocg_service_al.IOC_SAM_Utils');
daAjax.addParam('sysparm_name', 'datevalidation');
daAjax.addParam('sysparm_sys_ids', sysIDs);
daAjax.addParam('sysparm_end_date', newValue);
daAjax.getXML(dateResult);
function dateResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == -1) {
alert('End date cannot be before Start date');
saveAndClose = false;
}
else{
saveAndClose = true;
}
}
callback(saveAndClose);
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 05:34 AM
Hi @Amit Verma
Not working, after entering the date it is not aborting the action, even though if we add callback statements.
Not sure, if any one faced similar problem.
On change request. OOTB went with Business rules to abort the action.