onCellEdit Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 01:03 AM
Hello Experts,
I've written the script below to validate whether the start date is less than the end date or not. However, the script isn't functioning as expected. While I receive a proper confirmation message, when the start date is greater than the end date, it sets the start date field, which shouldn't happen. Instead, if the start date is greater than the end date, I want to revert the field to its old value. Please guide me on how to achieve this.
Thank you.
Oncelledit client script:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var ga=new GlideAjax('global.onCellEdit_Start_Date_Scnarios');
ga.addParam('sysparm_name','validateDates');//function name
ga.addParam('sysparm_sysid',sysIDs);
ga.addParam('sysparm_start_date',newValue);
ga.getXML(callBack_Response);
function callBack_Response(response)
{
var answer=response.responseXML.documentElement.getAttribute('answer');
if(answer=='Do Not Submit')
{
alert('please enter start date smaller than end date');
saveAndClose=false;
//newValue=oldValues;
}
else if(answer=='Submit it')
{
var confirmation=confirm("Are You Sure");
saveAndClose=confirmation;
}
}
callback(saveAndClose);
}
Script Include:
var onCellEdit_Start_Date_Scnarios = Class.create();
onCellEdit_Start_Date_Scnarios.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateDates:function()
{
var newDate=this.getParameter('sysparm_start_date');
var gr=new GlideRecord('incident');
gr.addQuery('sys_id',this.getParameter('sysparm_sysid'));
gr.addNotNullQuery('end_date');
gr.query();
if(gr.next())
{
if(newDate>gr.u_end_date)
{
return"Do Not Submit";
}
else if(newDate<=gr.u_end_date)
{
return "Submit it";
}
}
},
type: 'onCellEdit_Start_Date_Scnarios'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 01:42 AM
using onCell edit you cannot set field value.
you can simply stop the update
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 01:52 AM
I am not able to stop the update using above script.
Could you please advise on what mistakes I might be making here?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2024 01:43 AM
script looks fine to me. what debugging have you done so far?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 08:04 AM
Hi @Mark Wood ,
Did you manage to find a solution to this? If yes, can you please recall and provide some insights?