Formatting DateTime Field in Quick Messages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 11:15 PM
Hey everyone,
Is there a way we can change the display of glidedatetime type of field in quick messages...I tried using email script but it is not working...mail script is reflecting as it is..I have to display only date by formatting. I am using HTML type of body content.
Any better approach if anyone can suggest,
Getting output in this format: 2024-06-12 14:05:26 IST.
Should be displayed in this format: 2024-06-12
Thank you in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 11:39 PM
Hi @Utkarsha ,
You can paste your email script here for reference and debugging. I am providing the code below, your code should look something like this, you can use getByFormat function, assuming they are DateTime or Date format.
var mydateTime = current.date_time_field_name; // add the field name here
var formatedDate = mydateTime.getByFormat("yyyy-MM-dd");
email.body = 'Date is: '+ formatedDate;
For using different formats for the date variable you can take a look at this link : https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/GlideDateAPI#Glid...
Thanks,
Hope this help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2024 02:11 AM
Hi @Utkarsha ,
Please find the below code:
var time = '2024-06-12 14:05:26 IST';
var date = time.split(' ')[0];
gs.info(date +' ');
Here I splitted the string as space then it converted in array so we are now able to get the array position. On zero position, date is placed, 1 position is placed time and 2nd position zone is placed. Hope this will clear if you run this in background script.
Please accept my solution if it works for you and thumps up.
Thanks
Jitendra