Problem
You might have faced the below script error while working in CRM App for Outlook where a Date field is being set using the following syntax in JavaScript formContext.getAttribute("<fieldName>").setValue(Date.now());
Error: Value should be of type: DateTime
at h (https://<crmurl>/uclient/scripts/app.js?v=1.3.163-201103-224104:12:164)
at b (https://<crmurl>/uclient/scripts/app.js?v=1.3.163-201103-224104:12:327)
at t.prototype.setValue (https://<crmurl>/uclient/scripts/0.js?v=1.3.163-201103-224104:209:21956)
at setDateReceptionField (Unknown script code:561:13)
at e.prototype.executeFunction (https://<crmurl>/uclient/scripts/app.js?v=1.3.163-201103-224104:1659:50881)
at e.prototype.execute (https://<crmurl>/uclient/scripts/app.js?v=1.3.163-201103-224104:1659:50686)
at e.prototype._executeIndividualEvent (https://<crmurl>/uclient/scripts/app.js?v=1.3.163-201103-224104:1659:42649)
at e.prototype._executeEventHandler (https://<crmurl>/uclient/scripts/app.js?v=1.3.163-201103-224104:1659:41519)
at execute (https://<crmurl>/uclient/scripts/app.js?v=1.3.163-201103-224104:1659:39177)
Cause
This script error will appear when you use the function Date.now()
Resolution
In order to fix this, you have to change the way of setting the Date field that works on both CRM Application and Outlook App.
var today = new Date();
today.setDate(today.getDate());
formContext.getAttribute("kiwi_datereceptionappeloffre").setValue(today);
Bonus Tips:
- The function Date.now() does not work on the online version and you must use the new Date() approach
- The function Date.now() is still working on the on-premises version v9 but not on the App for Outlook if it is used
Hope This Helps!
*This post is locked for comments