- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 09:35 PM
Please help me on this iam started recently learning sNow.
I have two fields StartDate and EndDate . So Date/time validation needed done on server side. validate that minimum start date and end date 30 min if less than dont allow to form submission how to write scripting for this??
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 10:01 PM
Hi Vinu,
So here is the server side script; send startDate and endDate from onSubmit client script to script include using GlideAjax
This won't work in scoped app since it doesn't support dateDiff() method
getDifference: function(){
var startTime = this.getParameter('sysparm_startDate');
var endTime = this.getParameter('sysparm_endDate');
var start = new GlideDateTime();
start.setValue(startTime);
var end = new GlideDateTime();
end.setValue(endTime);
var diff = gs.dateDiff(start,end,true);
if(diff < 1800){
gs.info("Difference is less than 30mins");
return false;
}
return true;
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 10:01 PM
Hi Vinu,
So here is the server side script; send startDate and endDate from onSubmit client script to script include using GlideAjax
This won't work in scoped app since it doesn't support dateDiff() method
getDifference: function(){
var startTime = this.getParameter('sysparm_startDate');
var endTime = this.getParameter('sysparm_endDate');
var start = new GlideDateTime();
start.setValue(startTime);
var end = new GlideDateTime();
end.setValue(endTime);
var diff = gs.dateDiff(start,end,true);
if(diff < 1800){
gs.info("Difference is less than 30mins");
return false;
}
return true;
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 10:27 PM
Hi Ankur
Thank you for your reply I have done this on Script include but in OnSubmit() is less than 30 min it dont allow to submit but it is not working
Just check it my code
function onSubmit() {
//Type appropriate comment here, and begin script below
var sdt = g_form.getValue('u_start_date');
var edt = g_form.getValue('u_end_date');
var ga = new GlideAjax('ValidateDate');
ga.addParam('sysparm_name', 'addDateTimeAmount');
ga.addParam('sysparm_end_date', edt);
ga.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//var answer = ga.getAnswer();
if(answer == 'false')
{
alert("not available ");
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 11:07 PM
Hi Vinu,
Are those date/time fields or only date field.
Also check whether log is coming or not in script include and what time is getting printed in log. is your script include client callable?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 11:13 PM
Those are Date/time fields