- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 01:37 AM
Hi Team,
Can you please help me - attached script what is the result of it.
if there is any possible to keep start time & end time should not accept. how add this step in below script.
Onchange clientscript:-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 04:17 AM - edited 02-22-2023 04:22 AM
Hi @babbi ,
In the same onChange script add the below line of scripts and shown in image.
var startDate = g_form.getValue('start_date');
var endDate = g_form.getValue('end_date');
if (startDate == endDate) {
var errorMessage = "Planned end date must be after Planned Start Date";
g_form.clearValue('end_date');
g_form.showErrorBox("end_date", errorMessage);
return false;
}
Mark helpful and accept the solution if it helps in solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 04:31 AM
Try this
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
if(start == end){
var errorMessage = "Planned end date must be after Planned Start Date";
g_form.showErrorBox("end_date", errorMessage);
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2023 02:20 AM
Thanks for you help.
End time should take 10mints difference to start time.
below 10mints difference it should through error.
How to acheive ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2023 02:29 AM
var startDateTime = new Date(startDate);
var endDateTime = new Date(endDate);
var timeDiff = Math.abs(endDateTime.getTime() - startDateTime.getTime());
var diffMinutes = Math.ceil(timeDiff / (1000 * 60));
if (diffMinutes < 10) {
var errorMsg = "End date must be at least 10 minutes after the start date";
//alert(12);
g_form.clearValue("end_date");
g_form.showErrorBox("end_date", errorMsg);
return false;
Like this i have written but not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 09:05 AM
Hi @babbi ,
you cannot do this with by using client script alone. you need to use GlideDateTime and its a server side script, so here you need to use both Client script and script include.
Create a callable script include as per below pic.
Script include scripts:
changeDateValidation : function(){
var startDate = this.getParameter('sys_start_date');
var endDate = this.getParameter('sys_end_date');
var glideStartDate = new GlideDateTime(startDate).getNumericValue();
var glideEndDate = new GlideDateTime(endDate).getNumericValue();
var duration = glideEndDate - glideStartDate;
var minutes = duration/60000;
return minutes;
},
In the onChange client script do the modification in the script as per below image.
Full onChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
var showErrorMsg = function(errorMsg) {
g_form.showErrorBox("end_date", errorMsg);
};
g_form.hideFieldMsg("end_date", true);
var startDate = g_form.getValue('start_date');
var endDate = g_form.getValue('end_date');
if (startDate <= endDate) {
var ga = new GlideAjax('ValidateStartDateEndDate');
ga.addParam('sysparm_name','changeDateValidation');
ga.addParam('sys_start_date',startDate);
ga.addParam('sys_end_date',endDate);
ga.getXMLAnswer(callbackFunction);
}
if (validateStartDateBeforeEndDate("start_date", "end_date", showErrorMsg) && (typeof validateMaxDateDuration !== "undefined"))
validateMaxDateDuration("start_date", "end_date", showErrorMsg);
}
function callbackFunction (answer){
if(answer < 10){ //give the mins you want to validate
var errorMessage = "Planned end date must be 10 minutes after Planned Start Date";
g_form.clearValue('end_date');
g_form.showErrorBox("end_date", errorMessage);
return false;
}
}
Hope this helps your query.
Mark helpful and accept the solution if it helps in solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 04:31 AM
Try this
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
if(start == end){
var errorMessage = "Planned end date must be after Planned Start Date";
g_form.showErrorBox("end_date", errorMessage);
return false;
}