2.User should not able to enter "Start Date" value greater than of "End Date" value in the incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 07:53 PM
2.User should not able to enter "Start Date" value greater than of "End Date" value in the incident list view ?
Script include:-
var ScriptincludeDemo = Class.create();
ScriptincludeDemo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'ScriptincludeDemo',
cellEditGlide: function() {
var newDate = this.Parameter("sysparam_value");
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', this.getParameter("sysparam_id"));
gr.query();
if(gr.next()) {
if(newDate>gr.u_end_date)
{
return "AbortAction";
}
else if(newDate<=gr.u_end_date)
{
return "SubmitAction";
}
}
}
});
Client Script:-
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var ga = new GlideAjax('ScriptincludeDemo');
ga.addParam('sysparam_name', 'cellEditGlide');
ga.addParam('sysparam_id', sysIDs);
ga.addParam('sysparam_value', newValue);
ga.getXML(callscriptinclude);
function callscriptinclude(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == "SubmitAction") {
var confirmation = confirm("Are you sure that you want to change the Start Date");
callback(confirmation);
}
else if (answer == "AbortAction") {
alert("Start Date should not be greater than End Date");
callback(false);
}
}
callback(saveAndClose);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 08:03 PM
@Kongaleti Navee : This can be done in client side and please see the below code. Please change start_date and due_date with your field names.
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } if (g_form.getValue('start_date') == "") { g_form.clearValue('due_date'); g_form.showFieldMsg('due_date', "Please select a Start date first", 'error'); } var startDate = g_form.getValue('start_date'); var dueDate = g_form.getValue('due_date'); var startDateNum = getDateFromFormat(startDate, g_user_date_format); // change to g_user_date_time_format if field type is date/time var dueDateNum = getDateFromFormat(dueDate, g_user_date_format); // change to g_user_date_time_format if field type is date/time if (dueDateNum < startDateNum) { g_form.showFieldMsg('due_date', "The due date must be equal to or greater than the start date. Please select another date.", 'error'); } }
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 08:55 PM
Hello @Kongaleti Navee,
You can use below OnChange client script for your use case, so that User should not able to enter "Start Date" value greater than of "End Date" value in the incident.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sTime = g_form.getValue('u_glide_date_time_1'); //start Date
if (newValue < sTime) { //newValue is the End date
g_form.addErrorMessage('End Date should not be less than Start date');
g_form.setValue('u_glide_date_time_2', oldValue);
}
}
If the above solution resolved your issue, Please marked the answer as 'Accepted Solution' and also marked it as 'Helpful'.
Thank You!
Prathamesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 09:03 PM
2.User should not able to enter "Start Date" value greater than of "End Date" value in the incident list view ?I have taken the usecase from the basico servicenow youtube channel below link .where he used script include and OncellEdit clientscript.where did i do mistake ?why it is not working for me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 11:03 PM
Let's try my adjustment below.
#Script Include
var ScriptincludeDemo = Class.create();
ScriptincludeDemo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cellEditGlide: function() {
var newDate = this.getParameter("sysparm_value");
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', this.getParameter("sysparm_id"));
gr.query();
if (gr.next()) {
if (newDate > gr.u_end_date) {
return "AbortAction";
} else if (newDate <= gr.u_end_date) {
return "SubmitAction";
}
}
},
type: 'ScriptincludeDemo',
});
#Client Script
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var ga = new GlideAjax('ScriptincludeDemo');
ga.addParam('sysparm_name', 'cellEditGlide');
ga.addParam('sysparm_id', sysIDs);
ga.addParam('sysparm_value', newValue);
ga.getXML(callscriptinclude);
function callscriptinclude(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == "SubmitAction") {
var confirmation = confirm("Are you sure that you want to change the Start Date");
callback(confirmation);
} else if (answer == "AbortAction") {
alert("Start Date should not be greater than End Date");
callback(false);
}
}
callback(saveAndClose);
}
Cheers,
Tai Vu