Trying to set a two option field taxable on one form based on a lookup two option on account called taxable. RRS feed

  • Question

  • So I have a field on accounts that is two option (yes/no) called new_taxable in the accounts entity. I have a case form that I am able to populate customer information on based on the code below, however I think I am missing something as far as the datatype is concerned with option sets. Because when I pull the retirevedCustomer.new_taxable and try to alert it I get undefined. Can someone please help me understand how to fetch two option set values? Much appreciated. 
    function setphone() {
        var existingcustomer = Xrm.Page.getAttribute('new_customer').getValue();
        if (existingcustomer != null) {
            var serverUrl;
            if (Xrm.Page.context.getClientUrl !== undefined) {
                serverUrl = Xrm.Page.context.getClientUrl();
            } else {
                serverUrl = Xrm.Page.context.getServerUrl();
            var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
            var customerRequest = new XMLHttpRequest();
            customerRequest.open("GET", ODataPath + "/AccountSet(guid'" + existingcustomer[0].id + "')", false);
            customerRequest.setRequestHeader("Accept", "application/json");
            customerRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            if (customerRequest.status === 200) {
                var retrievedCustomer = JSON.parse(customerRequest.responseText).d;
                var mainphone = retrievedCustomer.Telephone1;
                var taxable = retrievedCustomer.new_taxable;
        } else { return; }

    Monday, June 23, 2014 10:14 PM

All replies

  • Hi,
    first you need to check if the OData request works, to do this just do an alert of mainphone, if it shows the right value OData works.

    If OData works and you get undefined with new_taxable probably new_taxable is not the schema name for the field, REST endpoint returns the schema name (upper case and lower case is relevant) so maybe your field is called new_Taxable instead of new_taxable.

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

    Tuesday, June 24, 2014 6:30 AM
  • Hi,

    The best way to check if your OData query is correct is to either use the OData Query Designer or simply hit the formed OData URL in a browser to check if you're getting a response. Guido is correct in the fact that the schema name is probably incorrect; generally the schema names are Camel Case instead of all lowercases. So, you might want to check that.

    Admin QuikView Solution for CRM 2013

    Tuesday, June 24, 2014 8:56 AM