- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 03:19 PM
For reporting purposes, I need to know what Month an inspection has been performed. This is a scoped application, so GlideDateTime doesn't work and neither does getMonth() as far as I can tell. I have been able to pull the month number, but the closest I have come is "undefined" when I am trying to get the Month name. I have a single client script onChange from the variable date field 'initial_inspection_date' and want to populate 'inspection_month' field with January or the correlating name.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var inspectionDate = g_form.getValue('initial_inspection_date');
var date = inspectionDate.split('-');
var monthNumber = date[1];
function getMonthNameFromMonthNumber(monthNumber)
{
var monthNames = ["January", "February", "March", "Arpil", "May", "June", "July", "August", "September", "October", "November", "December"];
return monthNames[monthNumber];
}
alert(getMonthNameFromMonthNumber(monthNumber)); //results in alert with "undefined"
//g_form.setValue('inspection_month',getMonthNameFromMonthNumber(monthNumber)); ---populates 'inspection_month' field with "undefined"
}
Any help is greatly appreciated!!!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 03:26 PM
Have you tried converting your month number from a string to an integer?
var monthNumber = parseInt(date[1], 10);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2017 10:00 PM
Hi Neal,
Thank you for the quick response.
Yes the field type for 'inf_cmt_preference1' is Date.
Client has requested to get the displayvalue as month and year.
When i tried using GlideDateTime() and GlideDate() functions i didnt see the flow progressing.I tried putting alerts and couldn't see them appearing .
Please find below the code which i used
var inspectionDate = g_form.getValue('inf_cmt_preference1');
var gDate = new GlideDate();
gDate.setValue(inspectionDate);
alert(gDate);
var gDT = new GlideDateTime(gDate);
alert(gDT);
Note:- We are using a scoped application, I don't think GlideDateTime() would work.
If i try to put this as a string field how would i get the date picker button in which an enduser should be allowed to select a date based on which month would get populated.
Regards,
Zabeeulla.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 07:12 AM
Hello Z,
Please confirm: requirement is to have a field with a date picker (calendar icon), and you also need to display the result as "MonthName Year"
If that is the case, in my opinion, you can only achieve this by having two separate fields within the standard SN interface. The SN date field is rigid as to the display format and I would not suggest tampering with that. I would also suggest you set up the two fields as "entry" and "display" for the UI. Example:
field one: Please select a date
type: date
suggest onLoad client script to clear value for this field
field two: Inspection date
type: string
Client Script onChange for 'please_select_a_date' to set your "MonthName Year" display
Also, your code above needed to be changed to something more like this...
You have to insert the inspectiondate value into your GlideDateTime as so:
Please find below the code which i used
var inspectionDate = g_form.getValue('inf_cmt_preference1');
var gDate = new GlideDateTime(inspectionDate);
alert(gDate.displayValue());
Hopefully this will help move you along...Let me know if this helps correct your solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 08:20 AM
Thanks Brian! I figured something like that.
greatly appreciated!