locked
SDK.REST.retrieveRecord optionset value RRS feed

  • Question

  • I'd love to get the optionset label but I'd be impressed just to find out what it's value is:

            if (Xrm.Page.getAttribute("parentaccountid") != null && Xrm.Page.getAttribute("parentaccountid").getValue() != null) {
    alert("in company " + Xrm.Page.getAttribute("parentaccountid").getValue()[0].id.toString());
                var CustomerType = null;
                SDK.REST.retrieveRecord(
                    Xrm.Page.getAttribute("parentaccountid").getValue()[0].id.toString(),
                    "Account", "swg_CustomerType", null,
                    function (Account) { alert("way in " + Account.swg_CustomerType); },
                    function () { });
                if (CustomerType != null) alert(CustomerType.Value);
                newName = Xrm.Page.getAttribute("parentaccountid").getValue()[0].name + " - " + newName;
    alert("on the way out");
            }
    

    this says "way in [object object]"  I've tried .Value, .Label, .Text and even .getText().  Nothing.

    What do I do to get this?

    Tuesday, July 1, 2014 11:22 PM

Answers

  • if your optionset name is swg_CustomerType the code

    eval(Account.swg_CustomerType.Value)

    is correct.

    because you said that before you got [object Object] when you alert Account.swg_CustomerType, try to do this alert

    alert(JSON.stringify(Account.swg_CustomerType));
    

    you will get something like ...metadata...Microsoft.Crm.Sdk.... Value... (your integer value)


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by mardukes Sunday, July 13, 2014 5:24 PM
    Sunday, July 13, 2014 2:13 PM

All replies

  • Hi,
    the REST endpoint returns only the integer value of the optionset.

    Another user had the same requirement before, I provided a method in his thread, you can check it (read all the thread, the method is at the end)

    http://social.microsoft.com/Forums/en-US/e438dc0b-2a87-4393-ae73-1c79aa9073e6/could-not-retrieve-option-set-value-from-parent-object-using-javascript?forum=crmdevelopment


    My blog: www.crmanswers.net - Rockstar 365 Profile


    Tuesday, July 1, 2014 11:32 PM
  • A lovely function.  However, I'm stuck in the middle.  My question is, "how to get the value of the option set."

    The link suggests "function (Account) { alert("way in " + eval(Account.swg_CustomerType.Value)); }

    The alert reads, "way in undefined"

    Please share with me the expression that will replace the "undefined" with the value to which the option is set.
    Sunday, July 13, 2014 1:07 PM
  • if your optionset name is swg_CustomerType the code

    eval(Account.swg_CustomerType.Value)

    is correct.

    because you said that before you got [object Object] when you alert Account.swg_CustomerType, try to do this alert

    alert(JSON.stringify(Account.swg_CustomerType));
    

    you will get something like ...metadata...Microsoft.Crm.Sdk.... Value... (your integer value)


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by mardukes Sunday, July 13, 2014 5:24 PM
    Sunday, July 13, 2014 2:13 PM
  • My problem seems to be that changes in the script don't find their way to the form.  I've tried saving and/or publishing the script, the form and the entity and I cannot predict when the changes will take effect.

    Ah!  current health is in extended recovery!

    • Edited by mardukes Sunday, July 13, 2014 5:29 PM
    Sunday, July 13, 2014 5:26 PM