How to set Catalog item variable date/time to display short date/time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 01:16 PM
I want the Catalog Item variable of date/time (could be single line text) in the service portal to NOT show seconds or milliseconds.
I understand this can be set on the display for user preferences, however, two things, it is already set to not show seconds and I have found this is not applying it to the catalog item within the service portal and not in the notifications when it displays this variable.
I was looking at something like the below, but I don't see how I can apply this to the variable type date/time.
var gd = new GlideDate();
var displayValue = gd.getDisplayValue();
gs.info('Display Value: ' + displayValue); // Output: Display Value: 11-13-2023
or can I add this to my notification?
=FormatDateTime(variablename, DateFormat.ShortDate)
Thanks in advance.
Nick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:09 PM - edited 03-01-2024 03:09 PM
Hi @Nicholas Hromya ,
Instead of coding you can change the catalog Item Variable field "type" to "Date" which will give you date in yyyy-mm-dd format without any time values,
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:32 PM
Hello @swathisarang98
I still want the hour and minutes, just not the seconds.
So, yah, the
var gd = new GlideDate()
is not enough...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:43 PM
@Nicholas Hromya , You can create a onload script to set the value of that field to show date and time as below, making sec as 00
function onLoad() {
var value = g_form.getValue('date');
var dateTime = value.split(' ')[0];
var sec = value.split(' ')[1].split(':');
var result = dateTime + ' ' + sec[0] + ':' + sec[1] + ':' + '00';
g_form.setValue('date', result);
}
But it will not work for form view in portal so in client script you need remove check box likeApplies on a Catalog Item view
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:53 PM
@Nicholas Hromya there is one more way to make sure all Date/time field gives hours and minutes but it might be global change which can effect other configuration
System properties -> system - Time format
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang