- 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
‎04-15-2025 08:08 AM
I had the same issue in the Configurable Workspace and I was able to monkey-patch it the following way:
- onLoad Task Client Script (Inherited=true):
function onLoad() {
try {
if (typeof g_user_date_format === 'undefined' || !g_user_date_format) {
g_user_date_format = ux_globals.session.output.user.dateFormat;
}
if (typeof g_user_date_time_format === 'undefined' || !g_user_date_time_format) {
g_user_date_time_format = ux_globals.session.output.user.dateTimeFormat;
}
if (typeof g_first_day_of_week === 'undefined' && typeof g_scratchpad.g_first_day_of_week !== 'undefined') {
g_first_day_of_week = g_scratchpad.g_first_day_of_week;
}
} catch (e) {
console.error('Fixing the global variables for the Workspace failed', e);
}
}
- onDisplay Task Business Rule:
(function executeRule(current, previous /*null when async*/ ) {
g_scratchpad.g_first_day_of_week = parseInt(gs.getProperty('glide.ui.date_format.first_day_of_week', 1));
})(current, previous);
The Client Script was mainly inspired by this script (see the evaluateTermDate function):
https://<instance>.service-now.com/scripts/sn/common/clientScript/uiPolicyFactory.js