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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to retrieve entity logical name using guid

(0) ShareShare
ReportReport
Posted on by 155

I have relationship like 

Account --> Appointment = 1:N

Distribution Office --> Appointment = 1:N

Appointment --> App Doc = 1:N

You can create an appointment either from Account or Distribution office. After appointment is created, an App doc is created. I need to display the contacts associated with either account or distribution office on App doc entity form.

I did an API call by passing the lookup attribute and got the regardingobjectid_value of the appointment (see below). Now i want to know the logical name of this regardingobjectid_value so that i will know if it created from account or distribution office.

var appid = window.parent.Xrm.Page.getAttribute("new_origmeeting").getValue()[0].id.toString();

req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/appointments(" + appid + ")?$select=_regardingobjectid_value", false);

How do i get the entity logical name by using regardingobjectid_value in javascript ??

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: How to retrieve entity logical name using guid

    You will get logical name of Regarding Object Id in result set.

    Complete sample code will be

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/appointments(3C81E020-A4CE-E511-80B9-005056B11FF6)?$select=_regardingobjectid_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 _regardingobjectid_value = result["_regardingobjectid_value"];

               var _regardingobjectid_value_formatted = result["_regardingobjectid_value@OData.Community.Display.V1.FormattedValue"];

               var _regardingobjectid_value_lookuplogicalname = result["_regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    Make required changes in code, and highlighted line will give you logical name of regardingobjectid lookup. 

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: How to retrieve entity logical name using guid

    You need to add a request header to include that information to your request:

    setRequestHeader("Prefer", "odata.include-annotations=*")

    Then you will be able to get the response using

    _regardingobjectid_value@OData.Community.Display.V1.FormattedValue

    See the following blog article for inogic, which describes this in further detail:

    www.inogic.com/.../querying-data-in-microsoft-dynamics-crm-2016-using-web-api

    Hope this helps.

  • Itz_Me_Ram Profile Picture
    155 on at
    RE: How to retrieve entity logical name using guid

    Already tried that but it is returning undefined..This works fine when i create an appointment from contact entity but the issue is only with account entity.

    function RetriveAppointmentContact() {

               var req = new XMLHttpRequest();

               var appid = window.parent.Xrm.Page.getAttribute("new_origmeeting").getValue()[0].id.toString();

               appid = appid.replace('{', '');

               appid = appid.replace('}', '');

               req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/appointments(" + appid + ")?$select=_regardingobjectid_value", false);

               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 _regardingobjectid_value = result["_regardingobjectid_value"];

                           var _regardingobjectid_value_formatted = result["_regardingobjectid_value@OData.Community.Display.V1.FormattedValue"];

                           var _regardingobjectid_value_lookuplogicalname = result["_regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

                           GetAccount(_regardingobjectid_value);

                       } else {

                           Xrm.Utility.alertDialog(this.statusText);

                       }

                   }

               };

               req.send();

           }

    Appointment created via contact :

    {"@odata.context":"test.crm.dynamics.com/.../v8.2$metadata#appointments(_regardingobjectid_value)/$entity","@odata.etag":"W/\"598155\"","_regardingobjectid_value@OData.Community.Display.V1.FormattedValue":"Eli manning","_regardingobjectid_value@Microsoft.Dynamics.CRM.associatednavigationproperty":"regardingobjectid_contact_appointment","_regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname":"contact","_regardingobjectid_value":"ee142714-61c5-e711-a950-000d3a34a108","activityid":"9c89632f-61c5-e711-a950-000d3a34a108"}

    Appointment created via Account :

    {"@odata.context":"test.crm.dynamics.com/.../v8.2$metadata#appointments(_regardingobjectid_value)/$entity","@odata.etag":"W/\"604940\"","_regardingobjectid_value":"436e35cb-9ac8-e711-a951-000d3a34ae50","activityid":"6ec37f50-a1c8-e711-a951-000d3a34ae50"}

    Thanks..

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans