Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id : DTvn/9f+GiH2U/8xMMVncL
Microsoft Dynamics CRM (Archived)

TypeError: Cannot read property 'getFullYear' of null

Like (1) ShareShare
ReportReport
Posted on 7 Aug 2015 15:35:03 by

Hello !

I am currently facing a Javascript error.

I have on a form (Transaction) the following fields: Transaction Name, Customer, Point of Sale and Transaction Date.

I am trying to display on the field Transaction Name, the concatenation of 3 others fields: Customer ID, Point of Sale SAP Code, and Transaction Date.

The Transaction Date must be displayed with the format YYYYmmdd.

Here is my javascript code, that is triggered on Save event (to lighten the post, I won't display the retrieve record function):

// Create the yyyy-mm-dd string of the Transaction Date

var transactionDate = CrmProject.UIBase.getAttributeValue("ava_transactiondate");
var year = transactionDate.getFullYear() + "";
var month = transactionDate.getMonth() < 9 ? "0" + (transactionDate.getMonth() + 1) : (transactionDate.getMonth() + 1);
var day = transactionDate.getDate() < 10 ? "0" + transactionDate.getDate() : transactionDate.getDate();
var dateFormat = year + month + day;

//[Here the retrieve record function] [...]

var concatenation = customer.ava_ContactID + "-" + pos.ava_SapCode + "-" + dateFormat;
CrmProject.UIBase.setAttributeValue(transactionName, concatenation);

When I fill the 3 fields Customer, Transaction Date and Point of Sale, after saving, everything is working without any error.
But, the problem is when I fill only the field Customer, when I am trying to save, I've got the following error message, because the Transaction Date is not filled:

TypeError: Cannot read property 'getFullYear' of null

 

So, to solve this problem, I would like to fill automatically the field Transaction Date with Today's Date, just when the page is loading, without saving. And I don't want to define the field Transaction Date as required.

How should I do?

 

Thank you for your help

 

Emmanuelle

*This post is locked for comments

  • Royal King Profile Picture
    27,686 on 07 Aug 2015 at 17:32:50
    RE: TypeError: Cannot read property 'getFullYear' of null

    try with below code.May be trasactuion date is null but you are trying to get the value of it. So i just added null check to it

    var transactionDate = Xrm.Page.getAttribute("ava_transactiondate").getValue();

    if (transactionDate != null)

    {

       var year = transactionDate.getFullYear() + "";

       var month = transactionDate.getMonth() < 9 ? "0" + (transactionDate.getMonth() + 1) : (transactionDate.getMonth() + 1);

       var day = transactionDate.getDate() < 10 ? "0" + transactionDate.getDate() : transactionDate.getDate();

       var dateFormat = year + month + day;

       var concatenation = customer.ava_ContactID + "-" + pos.ava_SapCode + "-" + dateFormat;

       CrmProject.UIBase.setAttributeValue(transactionName, concatenation);

    }

  • Suggested answer
    flavia.takushi Profile Picture
    on 07 Aug 2015 at 17:29:55
    RE: TypeError: Cannot read property 'getFullYear' of null

    Hi Emmanuelle,

    If you are using CRM 2015 Update 1, you can create a calculated field called Transaction Date and define the action as NOW(). This will bring the current date.

    If you don`t want to create a new field, you can use javascript code. Please check the link below so you can field an example:

    https://community.dynamics.com/crm/f/117/t/148982

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,760 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Loading started