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