web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Get parent Account name from a contact

(0) ShareShare
ReportReport
Posted on by 249

hello everyone,

i try to get the  parent Account  from a Contact in the Phone call entity (call to). 

this is my code  the problem that i dont know how i can come back the result . i need the (parentcustomerid_value_formatted us return)

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/contacts(b3859a95-1a0a-ea11-a811-000d3ab200b5)?$select=_parentcustomerid_value", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);

var _parentcustomerid_value = result["_parentcustomerid_value"];
var _parentcustomerid_value_formatted = result["_parentcustomerid_value@OData.Community.Display.V1.FormattedValue"];
var _parentcustomerid_value_lookuplogicalname = result["_parentcustomerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
return _parentcustomerid_value_formatted;
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    According to your code you use async call but use return trying to return the name of account. It doesn't work that way because call is executed in async way and function leaves execution before your retrurn statement is called.

    Can you please provide your full code because current version doesn't look complete.

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Since you want to get the parent account in Dynamics 365, I suggest to use "Xrm.WebApi.retrieveRecord" to get the value in a eaiser way.

    function GetParentAccount(executionContext) {
        var formContext = executionContext.getFormContext();

        //get if the contact allows to have a phone call.
        Xrm.WebApi.retrieveRecord("contact""91af308b-a11b-ea11-a828-000d3a579c9f","?$select=_parentcustomerid_value").then(
            function success(result) {
                var result = JSON.parse(this.response);

                var _parentcustomerid_value = result["_parentcustomerid_value"];
                var _parentcustomerid_value_formatted = result["_parentcustomerid_value@OData.Community.Display.V1.FormattedValue"];
                var _parentcustomerid_value_lookuplogicalname = result["_parentcustomerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

            },
            function error(error) {
                Xrm.Navigation.openAlertDialog({ text: error.message });
            }
        );


    }

    pastedimage1576548328902v1.png

    The result is allready in json format, and you just need to get each value you need to set them to fields or other containers.

    Best Regards,

    Leo

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans