We do have a multiple forms on servicenow that has a date field. All date field could only accept this default format YYYY-mm-dd. And when the user will going to change the default date format on their servicenow profile/settings and then fill-up and submit the form that has a date field, the result is that the date value going to be invalid due to invalid date format. How can I make the format static regardless of the users date format settings on servicenow? Thanks.
Asked
Active
Viewed 1,333 times
0
-
4Welcome to Stack Overflow! Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output. – mplungjan Jun 12 '18 at 09:47
1 Answers
0
var val = g_form.getValue('your_date_field');
if(getDateFromFormat(val, g_user_date_time_format) === 0){
//invalid date
g_form.addErrorMessage("Date is invalid")
}else{
//success, you have valid date
}
Make use of current user profile properties:
g_user_date_time_format //gives date time format
g_user_date_format // date format
g_user_decimal_separator // for number decimal separator
g_user_grouping_separator // for number grouping
If you are doing at server-end use: gs.getDateTimeFormat()
GlideSession gs = GlideSession.getCurrent();
gs.getDateTimeFormat();

Sunil B N
- 4,159
- 1
- 31
- 52
-
Thanks Sunil B N. We have so many forms on different pages that has date field. Is it possible to make it global date format of YYYY-mm-dd regardless of the user settings date format? – r. wanders Jun 13 '18 at 01:24
-
That would be against user's preferences. But nevertheless, you can always save in single format. What is the business use case to restrict user to one format? – Sunil B N Jun 13 '18 at 01:33
-
yeah we need to make it to one format its because everytime the user change the date format on their profile settings, then any format form that has a date field when they submit it triggers an error and that will serve them as blockers and they cant proceed. – r. wanders Jun 14 '18 at 16:27