0

I'm trying to set focus on the address1_postalcode field during the contact form load event. However when the script is run it throws an error.

Code:

Xrm.Page.ui.controls.get('address1_postalcode').setFocus();

And here is the error message:

enter image description here

I want to seek your kind help/suggestion in this manner to resolve it.

Zach Mast
  • 1,698
  • 1
  • 10
  • 17
user2384794
  • 53
  • 1
  • 2
  • 13

2 Answers2

0

The error is telling you that your code

Xrm.Page.ui.controls.get('address1_postalcode')

is returning null. Try:

Xrm.Page.getControl("address1_postalcode").setFocus();

http://crmorion.blogspot.com/2013/10/how-to-set-focus-on-control-in-crm-2013.html

Zach Mast
  • 1,698
  • 1
  • 10
  • 17
0

The most likely scenario is that the field you are referencing is not on your form. Keep in mind, since CRM 2013 the address fields have been combined into a composite field, and I don't think you can directly access fields within a composite field.

You can add your field ('address1_postalcode') as a separate field on the form, then your code will work.

Note that using this approach results in some strange scenarios where the user may update your address1_postalcode field and these changes won't be reflected in the new composite address field.

Andrew
  • 1
  • 1