locked
Option Sets getText() method returns nothing in a field onChange event RRS feed

  • Question

  • Hi everyone,

    Hi have this function in the onChange event of an options set called "pch_userid".

    I'm basically trying to get the Text value of the selected option...

    The event does starts but the getText() method returns nothing. The alert always comes up empty...

    I added the function in the onChange event of the field "pch_userid" in the Form Properties...

    function SetUsedIdTextBox()
    {
    var selectedOptionSet = Xrm.Page.getAttribute("pch_userid").getText();
    alert(selectedOptionSet);  
    }

    Any idea ?

    Many thanks in advance... ( And yes I'm new to this... :)   )

    Friday, February 14, 2014 4:35 PM

Answers

  • Tx for your answer...

    Maybe it's because I'm new to CRM, but your method seems quite complicated in order to simply retrieve the text value of the currently selected item in an option set picklist.

    I'll ask my question differently...

    If I use the following piece of code, whatever the event, what should I expect to have in my variable selectedOptionSet if "pch_userid" is an option sets field.

    var selectedOptionSet = Xrm.Page.getAttribute("pch_userid").getText();

    Tx

    Friday, February 14, 2014 6:17 PM

All replies

  • Hi

    You are trying to get value of a field on change of field..

    try using it onsave event or onload of form..

    Friday, February 14, 2014 4:39 PM
  •  Thanks for your answer...

    Does it means that you never can get the value of a field in a onChange event of the same field ?

    Is the onSave event fired prior to the data actually being saved to the DB ? If I assign a value to a field will it get saved ?

    Thx again...  Newbie stuff... :D

    Friday, February 14, 2014 4:55 PM
  • I Tried in the onSave event and I still get nothing...

    would it have anything to do with the fact that I populate de option set field dynamicly in the onLoad event of the form ? The values that I load dynamicaly are showing up correctly in the option set field...

    Tx

    Friday, February 14, 2014 5:03 PM
  • Hi,

    AFAIK it does not depend on the event of the form. You could use the metadata services in CRM to retrieve the labels of the optionset. The regular methods only gives you the value of the optionset, but using the metadata you could achieve the labels. Have look at this link or this one for an example.


    Iranian Dynamics CRM Association | انجمن متخصصان ایرانی

    Friday, February 14, 2014 5:06 PM
    Moderator
  • Tx for your answer...

    Maybe it's because I'm new to CRM, but your method seems quite complicated in order to simply retrieve the text value of the currently selected item in an option set picklist.

    I'll ask my question differently...

    If I use the following piece of code, whatever the event, what should I expect to have in my variable selectedOptionSet if "pch_userid" is an option sets field.

    var selectedOptionSet = Xrm.Page.getAttribute("pch_userid").getText();

    Tx

    Friday, February 14, 2014 6:17 PM
  • I think I understood your question in bad way. In this way, absolutely! It gives you the label text. You maybe using the wrong field name or something like that you did not configured the handler in a true way.

    Iranian Dynamics CRM Association | انجمن متخصصان ایرانی

    Friday, February 14, 2014 8:27 PM
    Moderator