Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Javascript to get details from parent lookup entity

Posted on by 1,545

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();
}
}
};

*This post is locked for comments

  • yleclerc Profile Picture
    yleclerc 1,545 on at
    RE: Javascript to get details from parent lookup entity

    Thank you both!!! It's working now. I re-created both fields all in lower case and made the Xrm change.

    @Guido I wanted to use a workflow for this but the field needs to be updated as soon as the customerid is populated and we have a number of other mandatory fields before we can save the record. That why we turned to JS.

  • Verified answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: Javascript to get details from parent lookup entity

    Hi,

    Javascript is case sensitive, when you are setting value, at that time not using proper case for Xrm object.

    it should be

    Xrm.Page.getAttribute("new_alertecesa").setValue(check.new_alertecesanonpaye);

    NOT

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans