Javascript .getMonth() method isn't working anymore

  • 1
  • Problem
  • Updated 2 years ago
  • Solved
  • (Edited)
Hello all,

My apologies for potentially a silly question .. For a few months now, I've had a piece of JS code in my Skuid page that references the standard Javascript .getMonth() method. This code was working really well until last week, when all of a sudden, the page wouldn't load anymore. When I looked at the console, I saw the following error:

Uncaught TypeError: startDateJS.getMonth is not a function

Like I said, the code used to run just fine. In fact, this is a Skuid page I haven't modified since 6/8/2016 -- it was working fine when/since I last modified it, and started displaying this error last week. Has some setting in Skuid changed, or could there be some global setting on my end that I modified to cause this issue?

Thanks!
Aparna
Photo of Aparna Ananthasubramaniam

Posted 2 years ago

  • 1
Hi there!

Just wanted to see if anyone else was experiencing this issue / if anyone had suggestions for how to fix this?

Thanks so much!
Aparna
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Can you post your entire JS snippet? 
Here it is -- the offending line is
var month = startDateJS.getMonth();

And like I said, this code was working well up until a few weeks ago; I haven't modified anything on this page for 2 months.

Thanks for your help!
Aparna

------------------------------------------------------------

var field = arguments[0],
value = arguments[1];

var loanModel = skuid.model.getModel('Loan'),
firstRow = loanModel.getFirstRow(),
startDate = loanModel.getFieldValue(firstRow,'ACH_Next_Debit_Date__c'),
dueDay = loanModel.getFieldValue(firstRow,'Current_Due_Day__c'),
distDate = loanModel.getFieldValue(firstRow,'Distribution_Date__c');

var picklistEntries = field.metadata.picklistEntries;
picklistEntries.length = 0;

var startDateJS = skuid.time.parseSFDate(startDate);
var month = startDateJS.getMonth();
var year = 1900+startDateJS.getYear();

var dueDate = new Date(year, month, dueDay);
var labelDueDate = skuid.time.formatDate("D, MM d, yy",dueDate);

var eoMonth = new Date(year, month+1, 1);
var eoMonth = new Date(eoMonth-1);
var labelEOMonth = skuid.time.formatDate("D, MM d, yy",eoMonth);

var resume = false;

var distDateJS = skuid.time.parseSFDate(distDate);
if(eoMonth > distDateJS) {
picklistEntries.push(
{ value: eoMonth, label: labelEOMonth, defaultValue: true, active: true }
);
}

for (var i=1; i,eoMonth);

resume = false;

picklistEntries.push(
{ value: dueDate, label: labelDueDate, defaultValue: resume, active: true },
{ value: eoMonth, label: labelEOMonth, defaultValue: false, active: true }
);
}

// Run the standard picklist renderer for the given mode
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
Hi all - Just wanted to check again to see if anyone had thoughts about this?
Photo of Amy Dewaal

Amy Dewaal, Official Rep

  • 8,200 Points 5k badge 2x thumb
Aparna,

This is probably the case, but can you check to see if ACH_Next_Debit_Date__c is a date and not a date-time object? The skuid.time.parseSFDate will fail if given a date-time, and then you'd get the error message you saw about .getMonth not being a function. You might also check the permissions associated with that field and the account object. To further investigate your problem try these steps in the developer console (if the console commands don't work and you're on Chrome you'll have to switch to firefox or take away your salesforce header and footer, it's a problem documented in this post). To get to console in Chrome right-click your page and click inspect, and to get to console in Firefox right-click and click inspect element.

date = skuid.$M('Loan').data[0].ACH_Next_Debit_Date__c;

This pulls the value of ACH_Next_Debit_Date from the first row of the Loan model, and you should see a date here. The next step is 

sdjs = skuid.time.parseSFDate(date);

Now you should see a more human readable form of the date. Lastly, ask for sdjs.getMonth(); and you should get a number back. These steps will help you determine if the Next_Debit_Date field has data in it and if you have access to it. Here's a screenshot of what my console looked like after testing:



Thanks!
Amy
Thanks so much, Amy! That was really helpful - as it turns out, all of my test loans have matured, so I don't have data in many of my fields. Fancy that!

Anyways, I added a line to my code to handle the case where some of these fields are null and that solved all of my problems.

Thank you again for your help!
Photo of Amy Dewaal

Amy Dewaal, Official Rep

  • 8,200 Points 5k badge 2x thumb
Aparna,

Glad to hear you got it sorted out!

Thanks!
Amy