- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 06:15 AM
I am having two fields start date and end date in my form and am trying to check whether the end date is less than start date, if yes it should throw and error. The script that i wrote is working in native view, but not in agent workspace.
Can someone help me out
var start_date = g_form.getValue("u_outage_start_date");
var end_date = g_form.getValue("u_outage_end_date");
var format = g_user_date_time_format;
var isEndBeforeStart = compareDates(start_date, format, end_date, format);
if (isEndBeforeStart){
g_form.clearValue("u_outage_end_date");
g_form.showFieldMsg("u_outage_end_date", "Outage End Date should be after Outage Start Date", "error");
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 08:27 AM
Hi,
g_user_date_time_format seems not allowed in workspace
you can use GlideAjax
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
‎05-10-2022 07:28 AM
Hi Roshini,
I tried in my developer instance, format is not working in agent workspace. try like this
var start_date = g_form.getValue("u_outage_start_date");
var end_date = g_form.getValue("u_outage_end_date");
if (end_date < start_date) {
g_form.showFieldMsg("u_outage_end_date", "Outage End Date should be after Outage Start Date", "error");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 07:37 AM
This is not working as expected..i mean if am selecting start date as 24th april and then giving end date as 3rd may it is giving error message.
it's just calculating the date and not checking for month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 07:34 AM
Hello Roshini,
Can you please try below code:
var dateFormat=g_user_date_time_format;
var D_one = g_form.getValue("<first date>");
var D_two = g_form.getValue("<second date>");
var dateOneFormat = getDateFromFormat(D_one , g_user_date_time_format);
var dateTwoFormat = getDateFromFormat(D_two , g_user_date_time_format);
var difference=(dateOneFormat - dateTwoFormat );
Please let me know if this is helpful.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 08:19 AM
I guess format is not working in agent workspace