- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 01:40 PM
I wanted to add a 'Date Submitted Month' variable field to a catalog and have it grab the MONTH from 'Date Submitted' field. How do I go about pulling the month and returning it as string such as screenshot below
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 01:38 AM
you can use onChange client script on that Date Submitted variable and script like this
UI Type - ALL
Applies to Catalog Item - True
Script: It will take care of the logged in user Date format may be yyyy-mm-DD or mm-DD-yyyy etc
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
g_form.clearValue('variableName'); // give here the name of the variable where you wish to store the month name
if(oldValue != newValue){
var month = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var dt1 = new Date(getDateFromFormat(newValue, g_user_date_format));
var monthNumber = dt1.getMonth();
var name = month[monthNumber];
g_form.setValue('variableName', name); // give here the name of the variable where you wish to store the month name
}
}
Sample Script I tried:
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
08-31-2022 01:38 AM
you can use onChange client script on that Date Submitted variable and script like this
UI Type - ALL
Applies to Catalog Item - True
Script: It will take care of the logged in user Date format may be yyyy-mm-DD or mm-DD-yyyy etc
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
g_form.clearValue('variableName'); // give here the name of the variable where you wish to store the month name
if(oldValue != newValue){
var month = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var dt1 = new Date(getDateFromFormat(newValue, g_user_date_format));
var monthNumber = dt1.getMonth();
var name = month[monthNumber];
g_form.setValue('variableName', name); // give here the name of the variable where you wish to store the month name
}
}
Sample Script I tried:
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
04-23-2025 04:48 AM
Hello,
I used your script to get Month Name. But arrays starts from 0 to n-1, so if I get monthNumber as 4, I am getting Month name as May.
Is this same happened to you to?
What is the best way to get it right month in such case?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 05:55 AM
Can you post a new question and share all the details and tag me there as this is an old thread?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader