- 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 08:16 AM
Ok In that case, I believe you dont need above client script and script include as its changing format for user.
Lets have the same format which you are initially getting with my script
Now in Runscript of Record Producer just add below code
var gdt = new GlideDateTime(producer.employment_date);
var gtime1 = new GlideTime();
gtime1.setDisplayValue(producer.employment_date);
var formatDate = gtime1.getByFormat("yyyy-MM-dd");
current.employment_end_date = formatDate;
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 08:58 AM
The previous script doesn't work, I modified it but it still doesn't work
I've got an error
var employee = producer.user;
var date = producer.employment_end_date;
var gdt = new GlideDateTime(date);
var gtime1 = new GlideTime();
gtime1.setDisplayValue(producer.employment_end_date);
var formatDate = gtime1.getByFormat("yyyy-MM-dd");
var isRecordExist = new GlideRecord('sn_hr_core_profile');
if (isRecordExist.get('user', employee)) {
isRecordExist.employment_end_date = formatDate;
isRecordExist.update();
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 09:16 AM
Hi,
Did you check the record is present or not for that user in HR profile table?
Regards
Ankur
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-08-2021 09:30 AM
yes, user is present in HR profile table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 11:49 PM
Massive thanks to both of you
I'll move my second question to new post