Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Retrieve field value from a related entity on load

$
0
0

I know there are dozens of other threads out there that ask similar questions and I've tried multiple solutions from those threads but I can't seem to get it to work. I have a decimal value field on the user record for a base commission rate. On a custom entity for commission line item there is a commission rate decimal value field. When I create a new commission rate line item record I want to retrieve the commission base rate value from the owner and have it populate on the new entity record. Below is my code, it seems to run through but I always get the Error Message pop up instead of the field value populated. I'm wondering if the retrieve.responseText could be an issue since it's a decimal not text? But I'm just not sure. Can anyone see whats wrong in the code?

Thanks,
Trevor

if(Xrm.Page.getAttribute("ownerid").getValue() != null)
{
      var id = Xrm.Page.getAttribute("ownerid").getValue()[0].id;

    var _oPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc";
    var _retrieve = new XMLHttpRequest();
    _retrieve.open("GET", _oPath + "/User Set(guid'" + id + "')", true);
    _retrieve.setRequestHeader("Accept", "application/json");
    _retrieve.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    _retrieve.onreadystatechange = function () { RetrieveCommissionCallBack(this); };

    _retrieve.send();
}
}

function RetrieveCommissionCallBack(_retrieve)
{
    if(_retrieve.readyState == 4)
    {
        if(_retrieve.status == 200)
        {
            var _rate = JSON.parse(_retrieve.responseText).d;
            if(_rate.new_commissionrate.Value != null)
             {
                     Xrm.Page.getAttribute("new_commissionpercentage").setValue(_rate.new_commissionrate.Value);

             }
 
        }
        else
        {
            window.alert("There was an error retrieving Commission Base Rate Information");
        }
    }
}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>