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

Announcements

News and Announcements icon
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
    451 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans