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

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at
    RE: Get parent Account name from a contact

    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

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Get parent Account name from a contact

    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.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans