web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get a value from two option field using javascript - MS CRM 2013 Online

(0) ShareShare
ReportReport
Posted on by 4,585

I am using this code:

status = Xrm.Page.data.entity.attributes.get('fieldname').getValue();

alert(status);

alert("end");

And that is triggered by custom button which is working.

The alert(status) window pops up, but it is just empty. The final alert("end") window pops up correctly with text end. The fieldname field is a two option field.

*This post is locked for comments

I have the same question (0)
  • Hosk Profile Picture
    on at

    how is the two option field displayed - is it a checkbox

    if it's a checkbox it may be null.

    if null then it's false

  • TseiTsei Profile Picture
    4,585 on at

    No it is not null. And if I remember right from the CRM 2011, it should even say if the field is null. So is this field changed from CRM 2011?

  • Fameeda Yaseen Profile Picture
    441 on at

    Hi,

    please confirm filed is place on form.

    if its formate is option set. then check what is its default value selected.

  • TseiTsei Profile Picture
    4,585 on at

    It's type is "two options" and has a default value "0" with label "no".

    With this I get the label, at the same time when I get the empty value.

    Xrm.Page.getAttribute('fieldname').getText()

  • Hosk Profile Picture
    on at

    so is the field definitely on the form

    How are you displaying the field

    are you definitely selecting the correct field

    is the label value bringing back anything

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Tseitsei,

    It is actually should gieve you alert pop up with text false or true, depends on the value, 0 or 1, and should not be getting Null for this two options since only Yes/No, and you set the default value = 0 (No)

    How if you try use this?

    status = Xrm.Page.getAttribute("fieldname").getValue());

    alert(status);

    alert("end");

  • TseiTsei Profile Picture
    4,585 on at

    Yes, the field is on the form.

    The field is normally displayed like any other field.

    Correct field is selected.

    Label brings back the correct label value.

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi Tseitsei,

    It is actually should gieve you alert pop up with text false or true, depends on the value, 0 or 1, and should not be getting Null for this two options since only Yes/No, and you set the default value = 0 (No)

    How if you try use this?

    status = Xrm.Page.getAttribute("fieldname").getValue());

    alert(status);

    alert("end");

  • Suggested answer
    TseiTsei Profile Picture
    4,585 on at

    Thanks Aileen. I got this working. Using both Xrm.Page.data.entity.attributes.get('fieldname').getValue(); and  Xrm.Page.getAttribute("fieldname").getValue(); methods.

    I also noticed that somehow browsers remember the old javascripts if I don't remove everyting from the browsers cache. This is a little bit weird and makes the development a little bit frustrating. I used both Firefox and IE.

    With CRM 2011 I just need to force reload to test new scripts.

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Teseitsei,

    You should re-load the web page to get new Javascript working.

    If not, the developer tool will always refers to the same javascript.

    Nice to hear that, becau I tried using both code, it also worked.

    So your problem solved.

    Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans