- 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:06 AM
sorry
type of variable is Date type
"Also I assume you are asking user to enter date and that will get stored in the HR Profile record?" <--- Yes, correct
"Is it via some record producer? if yes then why not use record producer script for this" <--- script include function is called in record producer
that was the first calling script include without changing date format
var callSI = new HRScriptInclude().updateEmplEndDate()
right now I'm calling function shared by Prasad
var callSI = new HRScriptInclude().setDataFormat(producer, current)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 06:34 AM
Ok then lets try this
Create onchange catalog client script like this on employment_date field with below code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var cdt = g_form.getValue('employment_date');
var ga = new GlideAjax('Test1');
ga.addParam('sysparm_name','type');
ga.addParam('sysparm_abc',cdt);
ga.getXML(testing);
function testing(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('employment_date', answer);
}
}
Script include
var Test1 = Class.create();
Test1.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: function() {
var pg = this.getParameter('sysparm_abc');
var gdt = new GlideDateTime(pg);
var gtime1 = new GlideTime();
gtime1.setDisplayValue(pg);
var formatDate = gtime1.getByFormat("yyyy-MM-dd");
return formatDate;
}
});
Make sure you SI look like this
This will change the format on fly as soon as you change the field on record producer
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 07:15 AM
But that solution modify only date format for record located on HR profile?
Date format on record producer will remain the same?
Expected date format for User
Expected format
After updating Hr Profile format via record producer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 07:35 AM
The script which I have provide will convert date from MMMM dd, YYYY to yyyy-MM-dd on record producer. I though that is what you want.
I guess your requirement is
1. When user select the date it should be in MMMM dd,YYYY
2. When user submit the record producer the HR profile should have yyyy-MM-dd
Is that correct?
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 08:00 AM
correct