get user preference date format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2023 11:35 PM
Hi,
I want to get user preference date format and I have a form field called modified which is concat of u_last_update & u_updated_by. These two fields are not being displayed on the form I want to get user preference format and set it accordingly and use it on modified . Can I use onLoad script and use it? But how exactly I get the format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2023 12:55 AM
where are you using this? i.e. where are you writing this? is it at dictionary level?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2023 01:36 AM
@Ankur Bawiskar yes in function definition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2023 01:51 AM
then query sys_user table with logged in user's sysId and get the format and then convert it to that format
How is the value showing now and what are you expecting it to show?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2023 11:28 PM
@Ankur Bawiskar Can I directly do here in function field?If yes can you help with the script.
And also if user has set preference then the format is displayed on sys_user table else if someone has not set then the field is empty there.
Currently value is showing as its stored in backed dd-mm-yyyy. But if there is any other date field on form that is showing according to user preference. I want in the user preference format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2023 11:44 PM
HI @Akki1 ,
I trust you are doing great.
To achieve this, you can use an onLoad client script. Here's an example of how you can accomplish this:
function onLoad() {
// Get the current user's preferences
var userDateFormat = g_user.date_format;
// Retrieve the "modified" field on the form
var modifiedField = g_form.getControl('modified');
// Apply the user's date format to the "modified" field
modifiedField.setDisplayValue(userDateFormat);
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
