Changing date format in Service Portal Catalog Item Variable from "dd/MM/yyyy" to "MM/dd/yyyy"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2023 05:11 PM
Hello. I have a catalog item that has a variable date field called Expected Date (expected_date) where it inputs a date with the default format of "DD/MM/YYYY".
I want to make it so that the default value and any other value inputted in this field is always in a "MM/DD/YYYY" format without the need to change the System Property of the date format in the instance.
Is there any way to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2024 04:12 AM
You can achieve this by configuring the catalogue item Client Script:
Type: onLoad or onChange (depending on when you want the script to run).
Script:
function onLoad() {
formatDateToDDMMYYYY();
}
function formatDateToDDMMYYYY() {
var Expected Date = g_form.getValue('expected_date');
if (Expected Date) {
var dateObj = new Date(startDate);
var day = String(dateObj.getDate()).padStart(2, '0');
var month = String(dateObj.getMonth() + 1).padStart(2, '0'); // Months are zero-indexed
var year = dateObj.getFullYear();
var formattedDate = day + '-' + month + '-' + year;
g_form.setValue('expected_date', formattedDate);
}
}