DYNAMICS 365 HOW TO SET DATE FIELD IN APP FOR OUTLOOK
PROBLEM
You might have faced the following script error when setting a Date field in CRM App for Outlook in JavaScript using the method 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)
REASON
This script error will appear when you use the function Date.now().SOLUTION
In order to fix this, you have to change the way of setting the Date field that will work on both CRM Application and Outlook App as follows.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!
Comments
Post a Comment