- 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 11:26 PM
Hi Vinu,
Did you check by adding log statements? what difference is coming?
can you share your script include code?
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:29 PM
var ValidateDate = Class.create();
ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
addDateTimeAmount: function(){
var sDate = this.getParameter('sysparm_start_date');
var lDate = this.getParameter('sysparm_end_date');
//var sdate = gs.nowDateTime();
var diff = gs.dateDiff(sDate, lDate, true);
if (diff < 1800){
gs.info("script include");
return false;
}
else {
return true;
}
},
type: 'ValidateDate'
});
i think i want change first time format right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2019 11:35 PM
Hi Vinu,
what format is your date/time value is it YYYY-MM-DD HH:mm:ss?
can you check value of diff in gs.info(diff);
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-19-2019 02:37 AM
Hi Vinu,
Any update on this.
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-19-2019 05:34 AM
it is working but time is showing utc format but we want our local format