- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2021 01:07 AM
Hi,
How to change date format from YYYY-MM-DD to Month DD, YYYY (for instance May 07, 2021)?
script include function
getEmployeeDate: function() {
var grHRProfile= new GlideRecord('sn_hr_core_profile');
grHRProfile.addQuery('user', gs.getUserID());
grHRProfile.query();
if (grHRProfile.next()) {
var hrProfileData = {
employment_end_date: grHRProfile.getValue('employment_end_date'),
probation_end_date: grHRProfile.getValue('probation_end_date')
}
return JSON.stringify(hrProfileData);
}
I found similar solution but it's implemented in calculated value
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 05:34 AM
Hi Try this
getEmployeeDate: function() {
var grHRProfile = new GlideRecord('sn_hr_core_profile');
grHRProfile.addQuery('user', gs.getUserID());
grHRProfile.query();
if (grHRProfile.next()) {
var gdt = new GlideDate();
gdt.setDisplayValue(grHRProfile.getValue('employment_end_date'));
var endDate = gdt.getByFormat("MMMM dd,YYYY");
var gdt1 = new GlideDate();
gdt1.setDisplayValue(grHRProfile.getValue('probation_end_date'));
var probDate = gdt1.getByFormat("MMMM dd,YYYY");
var hrProfileData = {
employment_end_date: endDate,
probation_end_date: probDate,
};
return JSON.stringify(hrProfileData);
}
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 06:02 AM
This is a script include function used in the record producer to update the date value selected by the user.
MMMM dd, YYYY <--- this is the date format that is displayed to users.
YYYY- MM-dd <--- this is the ServiceNow format
I have to change date format only for User purpose
Let me try your solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 06:04 AM
Hi Kris,
Have you tried above script? Means user select MMMM dd, YYYY but automatically it should change to YYYY-MM-dd?
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 06:14 AM
User selects MMMM dd, YYYY, but it doesn't automatically change to YYYY-MM-dd by ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 06:30 AM
I'm change to setValue because it doesn't work with setDisplayValue.
But it's very strange because it updates the records, but with date not selected
For example, the value of the field in the profile HR is set to 2021-06-01, I select July 27, 2021 from the select box and the field HR is updated to 2021-06-08.
updateEmplDate: function(producer, current) {
var employee = producer.user;
var date = producer.employment_date;
var gdt = new GlideDate();
gdt.setValue(date);
var endDate = gdt.getByFormat("yyyy-MM-dd");
var isRecordExist = new GlideRecord('sn_hr_core_profile');
if (isRecordExist.get('user', employee)) {
isRecordExist.employment_date = endDate;
isRecordExist.update();
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 06:43 AM
Hi,
what type of variable you are using?
Is it not date variable?
Can you share your form image?
Also I assume you are asking user to enter date and that will get stored in the HR Profile record?
Is it via some record producer? if yes then why not use record producer script for this
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader