0

How can I get field value in Dynamics 365 with JavaScript? In browser console function Xrm.Page() return undefined. And when I try get some attribute like a

Xrm.Page.getAttribute("new_city").getValue();

receive error in browser console:

Unable to get property 'getValue' of undefined or null reference

1

5 Answers 5

1

There are two ways you can approach this issue

  1. In the 'target' dropdown in the top right corner of your Developer Tools window, switch to 'Client API Wrapper'. You should then be able to access the form with your javascript code. Your syntax is correct.

  2. Append the beginning of your code with frames at index 0

example:

    var city = frames[0].Xrm.Page.getAttribute('bah_city').getValue();

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

1

It seems that you havent select the right frame, in the upper left corner of the console you should changed to customScriptsFrame and execute you code

Hope it helps.

Regards

enter image description here

Comments

0

Xrm.Page() probably isnt a method that exists. Try Xrm.Page instead.

For Xrm.Page.getAttribute("new_city"), are you certain:

  • The field is on the form.
  • The field name is spelt correctly.

Comments

0

Your code: Xrm.Page.getAttribute("new_city").getValue(); should work.

Make sure you are using the Name exactly as it is seen in the Field Properties.

Comments

0

Possible reasons are given in other answers.

To avoid errors, always use null check.

if(Xrm.Page.getAttribute("new_city") != null)
    var city = Xrm.Page.getAttribute("new_city").getValue();

If you are using this field in header, then use this:

Xrm.Page.getAttribute("header_new_city").getValue();

If you are using this field in Business Process Flow, then use this:

Xrm.Page.getAttribute("header_process_new_city").getValue();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.