Skip to content

Arvind's CRM Blog

Everything related to Microsoft Technology..

  • Microsoft Dynamics 365
  • Power Platform
  • CRM and Azure Integration
  • Microsoft Dynamics CRM News & Update
  • SQL Server
  • Silverlight
  • .NET
  • About Me
  • Power Platform
  • Microsoft Dynamics 365
  • Power Platform
  • CRM and Azure Integration
  • Microsoft Dynamics CRM News & Update
  • SQL Server
  • Silverlight
  • .NET
  • About Me
  • Power Platform

Tag: connections

Retrieve related field value using oData Query


Sharing code which retrieves related record’s field data value (Connections) and parse the data based on relationship metadata type property.

function RetrieveConectionNames() {

if (Xrm.Page.ui.getFormType() != 1) {

var CurrentRecordID = Xrm.Page.data.entity.getId();

var PartnerGUID = CurrentRecordID.substring(1, 37);

var serverUrl = Xrm.Page.context.getClientUrl(); //JS Fix

var ODATA_ENDPOINT = “/xrmservices/2011/OrganizationData.svc”;

var ODATA_EntityCollection = “/ConnectionSet?$select=Record2Id,Record2RoleId,contact_connections2/EMailAddress1,systemuser_connections2/InternalEMailAddress&$expand=contact_connections2,systemuser_connections2”;

var ODATA_Filter1 = “&$filter=Record1Id/Id eq guid'” + PartnerGUID + “‘”;

var ODATA_Filter2 = ” and (Record2RoleId/Id eq guid’44F5CBE2-3B2F-E011-BBAB-00155DC94520′ or Record2RoleId/Id eq guid’04E4BA76-5D5F-E111-BF46-00155DC94520′ or Record2RoleId/Id eq guid’170AFFF8-3B2F-E011-BBAB-00155DC94520′ or Record2RoleId/Id eq guid’DA759615-93A2-E211-BBE9-002DD80B0CA0′ or Record2RoleId/Id eq guid’1EB23AA0-19BE-E311-9413-002DD80B0CA0’)”;

var ODATA_OrderBy = “&$orderby=Record2RoleId”;

var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Filter1 + ODATA_Filter2 + ODATA_OrderBy;

//Calls the REST endpoint to retrieve data

$.ajax({

type: “GET”,

contentType: “application/json; charset=utf-8”,

datatype: “json”,

url: ODATA_Final_url,

beforeSend: function (XMLHttpRequest) {

XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);

},

success: function (data, textStatus, XmlHttpRequest) {

var result = ”;

for (i = 0; i < data.d.results.length; i++) {

result += data.d.results[i].Record2RoleId.Name + ” – ” + data.d.results[i].Record2Id.Name + ” – “;

if (data.d.results[i].contact_connections2 != null) {

if (data.d.results[i].contact_connections2.__metadata.type == “Microsoft.Crm.Sdk.Data.Services.Contact”) {

result += data.d.results[i].contact_connections2.EMailAddress1 + “\r\n”;;

}
}

if (data.d.results[i].systemuser_connections2 != null) {

if (data.d.results[i].systemuser_connections2.__metadata.type == “Microsoft.Crm.Sdk.Data.Services.SystemUser”) {

result += data.d.results[i].systemuser_connections2.InternalEMailAddress + “\r\n”;;

}
}
}

Xrm.Page.getAttribute(“new_oabnames”).setValue(result);

Xrm.Page.data.entity.save();

},

error: function (XmlHttpRequest, textStatus, errorThrown) {

alert(‘Error: ‘ + ODATA_Final_url);

}

});

}

}

Note: Notice the double underscore(__) before metadata i.e __metadata.type

Hope this help you.

Share this:

  • Email
  • Print
  • Tweet
  • WhatsApp
  • More

Like this:

Like Loading...
Author Arvind SinghPosted on May 20, 2014Categories Microsoft Dynamics CRMTags connections, CRM 2011, CRM 2013, metadata, OData, relationshipLeave a comment on Retrieve related field value using oData Query

How Popular This Blog

  • 165,421 hits

Recent Posts

  • User Security Manager – My first XrmToolBox Plugin
  • SCRIPT1003: Expected ‘:’ Error in IE 11
  • Call Actions using Dynamics CRM Web API with Output Parameter
  • How to Create a, “No Code”, Lead Capture Solution
  • Retrieve more than 5000 records in Dynamics 365

  • Arvind Singh
    • User Security Manager – My first XrmToolBox Plugin
    • SCRIPT1003: Expected ‘:’ Error in IE 11
    • Call Actions using Dynamics CRM Web API with Output Parameter
    • How to Create a, “No Code”, Lead Capture Solution
    • Retrieve more than 5000 records in Dynamics 365
    • Retrieve Data Using Web API and FetchXml
    • Issue with Data Export Service Add-ons
    • Configure Dynamics 365 and Azure Service Bus Integration
    • Retrieve data from N-N relationship in CRM
    • Execute Workflow using Web API in Dynamics 365

Let’s Connect

  • LinkedIn
  • Twitter
  • Facebook
  • Google

Categories

  • Advance Find
  • Automation server can not create object
  • Command
  • CRM 2011
  • CRM and Azure Integration
  • CRM5
  • EXE
  • FetchXml
  • FilteredLookup
  • JScript
  • Lookup
  • Microsoft .NET
  • Microsoft Dynamics 365
  • Microsoft Dynamics CRM
  • REST
  • SAP GUI
  • Silverlight
  • SiteMap
  • SQL
  • SQL Server
  • Uncategorized
  • Web API

Pages

  • MS CRM 2011
  • .NET
  • About Me
  • CRM and Azure Integration
  • CRM Learning
    • DataAudit for Microsoft Dynamics CRM 4.0
    • Retrieve the Roles for a User
  • Customization Using JScript
    • Filtering lookup data in CRM 4
  • Dynamics 365
    • Warning message in event log for ASP.NET: The request has been aborted
  • Microsoft Dynamics CRM Tools
  • Power Platform
  • Silverlight
  • SQL Server

Top Posts

  • Differences between Data Migration and Data Import

Recent Comments

  • prudvireddy on Retrieve more than 5000 records in Dynamics 365
  • Configure Dynamics 365 and Azure Service Bus Integration — Arvind’s CRM Blog – SutoCom Solutions on Configure Dynamics 365 and Azure Service Bus Integration
  • rovine dreams riviera maya cancun location on AutoNumber Plug-In for Custom Entity In CRM 4.0
  • New electric longboard blog on AutoNumber Plug-In for Custom Entity In CRM 4.0
  • para on AutoNumber Plug-In for Custom Entity In CRM 4.0

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 701 other followers

March 2021
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031  
« Jul    

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Archives

  • Ajax
  • Append Text
  • attachEvent
  • Attach Event to CRM
  • AutoNumber
  • Azure
  • Azure Integration
  • backgroundColor
  • Blank.aspx
  • BulkDeleteFailures
  • Button
  • Create
  • Create Button
  • Create Button in CRM
  • CRM
  • CRM 4.0
  • CRM 2011
  • CRM 2013
  • CrmDiscoveryService
  • CRM Login
  • CrmService
  • Customization
  • Delete
  • Dynamics 365
  • DynamicsEntity
  • Email
  • Event
  • Exception
  • FetchXml
  • FiltededView
  • Get CRM Server Url from ISV
  • Hide Field
  • Hide Tab
  • Impersonation
  • Import
  • Impot
  • JavaScript
  • JScript
  • Lookup
  • Mandatory
  • Microsoft Dynamics 365
  • Microsoft Dynamics CRM
  • migrate
  • MS CRM 2011
  • OData
  • Plug-In
  • Plug-Ins
  • PlugIns
  • pop-up
  • RebuildIndex
  • Replace Field to a label
  • REST
  • REST Endpoint
  • Retrieve
  • Retrieve Data
  • RetrieveMultiple
  • Revoke Access
  • Send Email
  • SetFieldReqLevel
  • Sharing
  • Sharing record with Team
  • Silverlight
  • Silverlight with CRM 2011
  • SoapException
  • SQL
  • stunnware
  • Style
  • Template
  • Tools
  • Update
  • upgrade
  • WCF
  • Web API
  • WebService
  • Workflow

Blogroll

  • Jim Wang
  • Mahender Pal
  • Nishant Rana

RSS Microsoft Dynamics CRM Team Blog

  • An error has occurred; the feed is probably down. Try again later.
  • RSS - Posts
  • RSS - Comments
  • Microsoft Dynamics 365
  • Power Platform
  • CRM and Azure Integration
  • Microsoft Dynamics CRM News & Update
  • SQL Server
  • Silverlight
  • .NET
  • About Me
  • Power Platform
  • Microsoft Dynamics 365
  • Power Platform
  • CRM and Azure Integration
  • Microsoft Dynamics CRM News & Update
  • SQL Server
  • Silverlight
  • .NET
  • About Me
  • Power Platform
Arvind's CRM Blog Blog at WordPress.com.
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: