- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 03:47 AM
Hi Team,
We have a requirement where a field should display 'Wednesday, May 10, 2023' whenever we select a specific date in another date field in a catalog item.
Kindly let me know how this can be achieved.
Thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:56 AM - edited 05-31-2023 05:10 AM
Hi @Aakanksha Kotti ,
You need to create an onChange client script and script include to achieve this, please refer to the below scripts
I am assuming that the field in which you need to populate the long date is of type string.
1. onChange catalog client script, on change of Date field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var newDate = newValue;
var dateGA = new GlideAjax('DateUtils');
dateGA.addParam('sysparm_name', 'getFullDate');
dateGA.addParam('sysparm_date', newDate);
dateGA.getXMLAnswer(_response);
function _response(answer) {
g_form.setValue('<field_name>', answer);
}
}
Step 2: Create a client callable script include and name it DateUtils, use this script
var DateUtils = Class.create();
DateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFullDate: function() {
var date = this.getParameter('sysparm_date');
date = date.toString();
var gd = new GlideDate();
gd.setDisplayValue(date);
var fullDate = gd.getDisplayValueLang("full");
return fullDate;
},
type: 'DateUtils'
});
Example output: this is on incident form, it will behave the same on catalog form as well.
If my answer has helped with your question, please mark it as correct and helpful
Thanks,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:56 AM - edited 05-31-2023 05:10 AM
Hi @Aakanksha Kotti ,
You need to create an onChange client script and script include to achieve this, please refer to the below scripts
I am assuming that the field in which you need to populate the long date is of type string.
1. onChange catalog client script, on change of Date field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var newDate = newValue;
var dateGA = new GlideAjax('DateUtils');
dateGA.addParam('sysparm_name', 'getFullDate');
dateGA.addParam('sysparm_date', newDate);
dateGA.getXMLAnswer(_response);
function _response(answer) {
g_form.setValue('<field_name>', answer);
}
}
Step 2: Create a client callable script include and name it DateUtils, use this script
var DateUtils = Class.create();
DateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFullDate: function() {
var date = this.getParameter('sysparm_date');
date = date.toString();
var gd = new GlideDate();
gd.setDisplayValue(date);
var fullDate = gd.getDisplayValueLang("full");
return fullDate;
},
type: 'DateUtils'
});
Example output: this is on incident form, it will behave the same on catalog form as well.
If my answer has helped with your question, please mark it as correct and helpful
Thanks,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 02:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:59 AM
are you saying when user selects a date; that date has to be converted in the custom format?
can you explain with screenshots?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
