Is it possible to change dateTime field to 12 hour format without changing global settings?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 03:10 AM
Hey, I have a field that is auto-filled with the submission date after a forms status changes to submitted. Is it possible to have this field in a 12 hour format as opposed to a 24 hour format without changing the global settings?
Field:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 03:14 AM
I attempted to do this in a business rule but it did not work as it wasn't a valid dateTime format.
(function executeRule(current, previous /*null when async*/) {
//current.u_submitdate = gs.nowDateTime();
var currentDate = gs.nowDateTime();
var time = currentDate.slice(-8); //find out the hours and minutes of submission date. This is needed to change 24 hour time to 12 hour.
var hoursSubmitted = time.slice(0,2);
var minutesSubmitted = time.slice(3,5);
var amORpm = "am";
var myUserObject = gs.getUser(); //get users timezone.
var userTimezone = myUserObject.getTZ();
if(hoursSubmitted >= 12){
amORpm = "pm";
if(hoursSubmitted > 12){
hoursSubmitted = hoursSubmitted - 12;
}
}
var newTime12Hour = hoursSubmitted + ":" + minutesSubmitted + " " + amORpm;
var dateTime12Hour = currentDate.replace(time, newTime12Hour);
current.u_submitdate = dateTime12Hour;
gs.addInfoMessage(userTimezone + ' ' + time + ' HH:' + hoursSubmitted + ' MM:' + minutesSubmitted + ' newTime' + newTime12Hour + ' dateTime ' + dateTime12Hour);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 03:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 03:32 AM
Thanks for your help. It doesn't seem to let you change the dateTime field even in an onLoad client script using g_form.setValue if it's not the correct format? Or should I use something else and not g_form.setValue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 03:51 AM
Hi Shane,
I am afraid that even if we format the date as per our need but then its not gonna save it back in the system showing it as "invalid date".
All you can do is to set the display it in 12 hours format.
and yes you will have to take care of right format too.
That's all I could come up with at this point of time