web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

TypeError: Cannot read property 'getFullYear' of null

(1) ShareShare
ReportReport
Posted on 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

I have the same question (0)
  • Suggested answer
    flavia.takushi Profile Picture
    on at

    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

  • Royal King Profile Picture
    27,686 on at

    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);

    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans