I understand Xrm.Page has been depricated in Dynamics 365 V 9.x and I am trying to write my code the new way.
The original snippet I have that capitalizes the first character of every word in a text field is shown below, but since it is not V 9 compliant, as it contains Xrm.Page I am trying to re-write it.
function UpperCaseField(fieldName) { var value = Xrm.Page.getAttribute(fieldName).getValue(); //VALUE NOT NULL, CHANGE TEXT TO UPPERCASE if (value != null) { Xrm.Page.getAttribute(fieldName).setValue(value.charAt(0).toUpperCase() + value.substr(1).toLowerCase()); Xrm.Page.ui.clearFormNotification('1'); } //VALUE EQUAL TO NULL,DISPLAY WARNING NOTIFICATION else { Xrm.Page.ui.setFormNotification('Cannot be BLANK','WARNING','1'); } }
The re-written code shown below where I replaced Xrm.Page with the new formContext code
function UpperCaseField(fieldName) { var formContext = executionContext.getFormContext(); var value = formContext.getAttribute(fieldName).getValue(); alert (value); //VALUE NOT NULL, CHANGE TEXT TO UPPERCASE if (value != null) { formContext.getAttribute(fieldName).setValue(value.charAt(0).toUpperCase() + value.substr(1).toLowerCase()); formContext.ui.clearFormNotification('1'); } //VALUE EQUAL TO NULL,DISPLAY WARNING NOTIFICATION else { formContext.ui.setFormNotification('Cannot be BLANK', 'WARNING', '1'); } }
However, that doesn't seem to work and I get the following error
The contents of the error details file can be seen below.
UpperCaseField@this.url.has.been.redacted.for.security/.../GeneralApplicationFunctions.js @this.url.has.been.redacted.for.security/.../ClientApiWrapper.aspx line 159 > eval:1:1 RunHandlerInternal@this.url.has.been.redacted.for.security/.../ClientApiWrapper.aspx RunHandlers@this.url.has.been.redacted.for.security/.../ClientApiWrapper.aspx ExecuteHandler@this.url.has.been.redacted.for.security/.../ClientApiWrapper.aspx $De_1@this.url.has.been.redacted.for.security/.../formcontrols.js executeHandler@this.url.has.been.redacted.for.security/.../formcontrols.js executeHandlerByDescriptor@this.url.has.been.redacted.for.security/.../formcontrols.js getHandler/<@this.url.has.been.redacted.for.security/.../formcontrols.js getHandler/<@this.url.has.been.redacted.for.security/.../global.ashx fireOnChange@this.url.has.been.redacted.for.security/.../formcontrols.js setValueInternal@this.url.has.been.redacted.for.security/.../formcontrols.js setValue@this.url.has.been.redacted.for.security/.../formcontrols.js $48_2@this.url.has.been.redacted.for.security/.../formcontrols.js Function.createDelegate/<@this.url.has.been.redacted.for.security/.../MicrosoftAjax.js b@this.url.has.been.redacted.for.security/.../MicrosoftAjax.js trigger@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js trigger@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js e.event.trigger@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js trigger/<@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js each@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js each@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js trigger@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js n.fn[b]@this.url.has.been.redacted.for.security/.../jquery-2.1.1.min.js focus@this.url.has.been.redacted.for.security/.../jquery_ui_1.8.21.min.js revertFocusBackToValueContainer@this.url.has.been.redacted.for.security/.../formcontrols.js onKeyDownHandler@this.url.has.been.redacted.for.security/.../formcontrols.js Function.createDelegate/<@this.url.has.been.redacted.for.security/.../MicrosoftAjax.js b@this.url.has.been.redacted.for.security/.../MicrosoftAjax.js
I also tried re-writing another of of my snippets that did the same thing.
The original code is
function setFirstLetterToCapital(attributeName) { var attribute = Xrm.Page.getAttribute(attributeName); if (attribute != null) { var attributeValue = attribute.getValue(); if (attributeValue != null) { // Split into each word var attributeSplit = attributeValue.split(' '); for (var word in attributeSplit) { attributeSplit[word] = capitalizeWord(attributeSplit[word]); } var capitalized = attributeSplit.join(' '); attribute.setValue(capitalized); } } }
The re-written code is shown below.
function setFirstLetterToCapital(attributeName) { var formContext = executionContext.getFormContext(); var attribute = formContext.getAttribute(attributeName); if (attribute != null) { var attributeValue = attribute.getValue(); if (attributeValue != null) { // Split into each word var attributeSplit = attributeValue.split(' '); for (var word in attributeSplit) { attributeSplit[word] = capitalizeWord(attributeSplit[word]); } var capitalized = attributeSplit.join(' '); attribute.setValue(capitalized); } } }
The same problem occurs so clearly I am missing something.
What on earth am I missing?
Any help, advise, suggestions, or recommendations would be greatly appreciated.
*This post is locked for comments