Displaying month name instead of the month number

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a table that i'm trying to display the name of the month instead of the number.  I have:

<groupby method="simple"> 
           <field id="CreatedDate" name="cmCreatedDate" function="CALENDAR_MONTH"/>
</groupby>

I found this that should work to add the name, but i can't get it to work:

var d = new Date();

var CreatedDate = new Array();

CreatedDate[0] = "January";

CreatedDate[1] = "February";

CreatedDate[2] = "March";

CreatedDate[3] = "April";

CreatedDate[4] = "May";

CreatedDate[5] = "June";

CreatedDate[6] = "July";

CreatedDate[7] = "August";

CreatedDate[8] = "September";

CreatedDate[9] = "October";

CreatedDate[10] = "November";

CreatedDate[11] = "December";

var n = CreatedDate[d.getMonth()];

Any idea on what I'm doing wrong?

Thanks in advance for any help!

Kris


Photo of Kris

Kris

  • 574 Points 500 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Kris,

Are you using the above JavaScript code within a Snippet? Can you post the full snippet code? 
Photo of Kris

Kris

  • 574 Points 500 badge 2x thumb
Hi Zach,

Thanks for your note.  Here's what is in the snippet code:

var params = arguments[0], $ = skuid.$;
var d = new Date();
var CreatedDate = new Array();
CreatedDate[0] = "January";
CreatedDate[1] = "February";
CreatedDate[2] = "March";
CreatedDate[3] = "April";
CreatedDate[4] = "May";
CreatedDate[5] = "June";
CreatedDate[6] = "July";
CreatedDate[7] = "August";
CreatedDate[8] = "September";
CreatedDate[9] = "October";
CreatedDate[10] = "November";
CreatedDate[11] = "December";
var n = CreatedDate[d.getMonth()];
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Change to this:

var field = arguments[0],
   value = arguments[1];
// We will be handed months 1-12, so need to subtract 1
skuid.ui.fieldRenderers.TEXT.readonly(field,value ? skuid.time.monthNames[value-1] : '');
(Edited)
Photo of Kris

Kris

  • 574 Points 500 badge 2x thumb
I replaced everything in the snippet with what you put above, but it's still showing the number.  Did you want me to change the whole thing to be what you put?

Thanks Zach!
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
I should have prefaced my comments saying "Here are three ways you can do it"  choose one.    But you asked a few questions.  One represents a  "DOH" on my part and the other more intruiging. 

1. Entering the alias alone in your Option Template and Value properties is not enough.  The alias has to be wrapped in {{braces}} in order to do the data merge we are asking of it.  My bad...

2. If you see claims that have a created date for May 2015, that may be evidence of another issue.  You may really have claims for May of 2015 - which your report is filtering out.   Your formula field may be wrong.  It could be somthing else...
Photo of Kris

Kris

  • 574 Points 500 badge 2x thumb
ahhh..ok.  :-)  Well, i really like the 3rd option so I don't have to keep updating it each year.   Putting it in braces worked.  Didn't think of that.  :-)

I have gone through the report a couple times a couple of ways and there are not any claims w/ a date of May 2015.  I don't have any filters and if i filter by May 2015, I don't get anything.  The field is very simple - just a DATETIME field.  My table is grouped by this field using the CALENDAR_MONTH function.  

I think maybe this is the problem, it's using this snippet:

var field = arguments[0],    value = arguments[1];
// We will be handed months 1-12, so need to subtract 1
skuid.ui.fieldRenderers.TEXT.readonly(field,value ? skuid.time.monthNames[value] : '');
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Yep,  Zach included the comment but not the code.  If you count the detail claims you have for April 2015 - it will match what your summary is suggestind for May 2015.  I've updated Zach's code below.   You probably want to replace the whole thing rather than try to just add one line, because there are changes in the last line that I would miss... 

var field = arguments[0],
value = arguments[1],
valueAdjusted = value - 1
// We will be handed months 1-12, so need to subtract 1

skuid.ui.fieldRenderers.TEXT.readonly(field,value ? skuid.time.monthNames[valueAdjusted] : '');

Enjoy.. 
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Oops, I edited my post above. I meant to put -1 within the last line, like this:

var field = arguments[0],
    value = arguments[1];
skuid.ui.fieldRenderers.TEXT.readonly(field,value ? skuid.time.monthNames[value-1] : '');
Photo of Kris

Kris

  • 574 Points 500 badge 2x thumb
This worked great.  Thanks guys!!