- 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 05:29 AM
Hi
I did as you mentioned but it doesn't work.
endDate and probDate are empty
getEmployeeDate: function() {
var grHRProfile = new GlideRecord('sn_hr_core_profile');
grHRProfile.addQuery('user', gs.getUserID());
grHRProfile.query();
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");
if (grHRProfile.next()) {
var hrProfileData = {
employment_end_date: endDate,
probation_end_date: probDate,
};
return JSON.stringify(hrProfileData);
}

- 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 05:35 AM
I have tested this and working fine on PDI.
Try once and let me know if it doesn't work.
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 05:48 AM
works fine, many thanks
but after I changed date format I've faced another issue 🙂
One of those date values should be updated via record producer in field HR profile after submitting
updated field should be in format
How to modify updating script?
updateEmplDate: function(producer, current) {
var employee = producer.user;
var date = producer.employment_date;
var isRecordExist = new GlideRecord('sn_hr_core_profile');
if (isRecordExist.get('user', employee)) {
isRecordExist.employment_date = date;
isRecordExist.update();
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 05:56 AM
Hi Kris,
Can you please show me your complete script and where you using this?
So you mean to say you want to convert from MMMM dd, YYYY to YYYY-MM-dd
Then use this
updateEmplDate: function(producer, current) {
var employee = producer.user;
var date = producer.employment_date;
var gdt = new GlideDate();
gdt.setDisplayValue(producer.employment_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);
}
Thank you
Prasad