ServiceNow: Date and Time validation
Date and
Time format along with System timezone setting for ServiceNow instance can be
checked in System Properties à System.
Date format - use the same 'format' strings as the java.text.SimpleDateFormat class,
with minor exceptions. Note that MM is months, where mm indicates minutes. The
format string consists of the following abbreviations:
Field
|
Full
Form
|
Short
Form
|
Year
|
yyyy (4
digits)
|
yy (2 digits), y (2 or 4 digits)
|
Month
|
MMM
(name or abbr.)
|
MM (2
digits), M (1 or 2 digits)
|
Day of
Month
|
dd (2
digits)
|
d (1 or
2 digits)
|
For
example: yyyy-MM-dd
Time format - use the same 'format' strings as the
java.text.SimpleDateFormat class, with minor exceptions. The format string
consists of the following abbreviations:
Field
|
Full
Form
|
Short
Form
|
Hour
(1-12)
|
hh (2
digits)
|
h (1 or
2 digits)
|
Hour
(0-23)
|
HH (2
digits)
|
H (1 or
2 digits)
|
Minute
|
mm (2
digits)
|
m (1 or
2 digits)
|
Second
|
ss (2
digits)
|
s (1 or
2 digits)
|
AM/PM
|
a
|
Example:
HH:mm:ss
System timezone, used as default for
calendars and users. Olson/zoneinfo timezone values are accepted.
Examples:
Africa/Johannesburg
America/Toronto
America/Mexico_City
Antarctica/Vostok
Asia/Shanghai
Asia/Tokyo
Australia/Sydney
Europe/Berlin
Europe/London
US/Pacific
US/Mountain
US/Central
US/Eastern
For
example: UTC
Appropriate
validations are applied for required date and time fields on ServiceNow forms,
as different user may work on same instance in different timezone with respective
date and time settings.
To
restrict users from using different date time formats on ServiceNow forms,
Validation Scripts can be added for respective data type (like for e.g. Date
type) to conform with instance settings
function validate(value) {
if(!value)
{
return true;
}
return(getDateFromFormat(value,'yyyy-MM-dd') !=
0);
}
Client
scripts can also be written when field value is changed or ServiceNow form is
submitted.
function onChange(control, oldValue, newValue, isLoading)
{
if (isLoading
|| newValue == oldValue) {
return;
}
if (getDateFromFormat(newValue, 'yyyy-MM-dd
HH:mm:ss') == 0) {
//your
message for the date field - Invalid date
}
}
function onSubmit() {
if (getDateFromFormat(g_form.getValue('yourField'), 'yyyy-MM-dd
HH:mm:ss') == 0) {
//your
message for the date field - Invalid date
return false; // Stop
the form submit event
}
}
Date and
time format setting for the ServiceNow instance can be checked through scripts
as well
var rec = new GlideRecord(‘sys_properties’);
rec.addQuery(‘name’, ‘glide.sys.date_format');
rec.query();
if(rec.next()){
var yourPropertyValue
= rec.value;
gs.print(yourPropertyValue);
}
var rec = new GlideRecord(‘sys_properties’);
rec.addQuery(‘name’, ‘glide.sys.time_format');
rec.query();
if(rec.next()){
var yourPropertyValue
= rec.value;
gs.print(yourPropertyValue);
}
For custom
form validation (for e.g. in UI page), separate script include with
common functions (similar to client scripts logic) can be written to validate
field formatting. These functions can be called through GlideAjax method in
client script section of UI page.
interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts,Thanks a million once again, Regards servicenow training in hyderabad
ReplyDeleteServiceNow - Layman Learning
ReplyDeletelaymanlearning.com/servicenow
ServiceNow Training Courses: ServiceNow Accredited Administration Training ITIL® Accredited Training & Certification ITSM (Apollo) Simulation ISO20000 COBIT Six ..
Support; Query? +91-741-626-7887 ... Online Corporate IT training services. OnlineTraining | Corporate Training | Layman Learning. Email: hr@laymanlearning.com.
Very nice article. Thanks for your information.
ReplyDeleteservicenow now learning
servicenow online training
The Community-Driven Education is the best to help us and provide great results. The Project Ownership Where it Belongs is amazing and I like that you shared this post for us to know about these ideas. Also from 2V0-31.20 Exam Dumps Questions I realize that it is more helpful for us.
ReplyDelete
ReplyDeleteThank you for sharing wonderful information with us to get some idea about that content.
Servicenow Developer Training
Servicenow Training in Ameerpet
Servicenow Course Online
Best Servicenow Online Training
Servicenow Developer Training Online
Servicenow Admin Training Online
Learn Servicenow Online
Servicenow Developer Online Training
Servicenow Admin Online Training
Servicenow Online Training in India
Servicenow Online Training Hyderabad
Servicenow Online Training India
Too good article,keep sharing more posts with us.
ReplyDeletethank you....
Servicenow online training
Servicenow course online
Servicenow certification
Servicenow admin online training
servicenow online training india
servicenow online training hyderabad
servicenow course
ETL Testing online training
ReplyDeleteHadoop online training
Tibco online training
Tibco spotfire online training
Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man learn
ReplyDeletePega Training
Pega Course
Your blog is in a convincing manner, thanks for sharing such an information with lots of your effort and time
ReplyDeleteservicenow training
servicenow certification
servicenow developer online training
servicenow developer training
servicenow fundamentals training
itsm certification
Thank you for sharing the valuable information.
ReplyDeletepega testing
pega testing online course
pega testing training
Thank For sharing Valuable Information
ReplyDeleteServiceNow admin Training Online
ServiceNow admin Online Training
Thanks for your information. very good article.
ReplyDeleteServiceNow developer certification
itsm certification