Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Javascript to get details from parent lookup entity

$
0
0

In a case (incident), upon customerid selection, I'm trying to populate a field from the account.that is looked up. I'm trying the code below but nothing happens.

I don't want to use quickview because I will have behaviors related to the field in the case.

The field in the case is: new_alertecesa

The field in the account is: new_alertecesanonpaye

Both are two-options type of field. So if the box is checked on the account, I want the box to auto-check when a customer is selected in a new case.

Any help is appreciated:

function updatealertecesa() {

var parent = Xrm.Page.getAttribute("customerid").getValue();

if (parent != null) { //Perform any basic checking to make sure we have a valid starting value
if (parent[0].entityType == "account") {

 

var accountId = parent[0].id;

 

var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + accountId + "')?$select=new_alertecesanonpaye";

 

var request = new XMLHttpRequest();
request.open("GET", oDataSelect, false); //false = synchronous, true = asynchronous
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", "application/json;charset=utf-8");
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200) {

 

var check = JSON.parse(request.responseText).d;

//Change form data

XRM.Page.getAttribute("new_alertecesa").setValue(check.new_alertecesanonpaye);
}
}
};
request.send();
}
}
};


Viewing all articles
Browse latest Browse all 46379

Trending Articles



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