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
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..
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.
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156