Microsoft Dynamics CRM 365 Query operations with $expand option
Tags: microsoftdynamics365, query, crm, tutorial
Published: 2021-08-11 13:04:13

---
title: Microsoft Dynamics CRM 365 Query operations with $expand option
published: true
date: 2021-03-22 09:39:54 UTC
tags: #microsoftdynamics365, #query, #crm, #tutorial
canonical_url: https://tech.forums.softwareag.com/t/microsoft-dynamics-crm-365-query-operations-with-expand-option/239887/1
---

## Summary:

This article describes the use case for Query operations of **Microsoft Dynamics CRM 365** Connector with the **$expand** function in the on-premise

## Prerequisites:

• The user needs to have a working account for **Microsoft Azure Active Directory** and a **Microsoft Dynamics CRM 365** license to access the API  
  
• License for the **Integration server 10.3** or above

## Contents:

We will analyze the various options of querying the business objects, Example: **$expand** & **filters** in the **Microsoft Dynamics CRM 365** using **Query Operation** service in the Connector. More information can be found at [Basic Tutorial · OData - the Best Way to REST](https://www.odata.org/getting-started/basic-tutorial/#expand)

## Steps:

1. User needs to start the **Integrations Server** and open **Designer** along with the latest **Microsoft Dynamics CRM 365** package installed, also the Connection should be established
2. Once the Server gets started, the user needs to create the **CCS (cloud connector service)** for the **query** operation available in the Connector. In this example, we will query the **Accounts** business object
3. To create the **CCS** , choose any folder and Right-click to choose **New → Cloud Connector Service** Option
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/2/2ec22e7d332df74642640a622c69509243a37a34.png)
4. Enter any name for the **CCS** as per user requirements, Example: **queryAccounts**
![image](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/8/8129616071de4ae251f7aa50ae81832ebc46bb2a_2_515x500.png)
5. Now choose the **Microsoft Dynamics 365 CRM** option from the available Connectors list and click **Next**
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/b/b6301feacd1aec1eb7dd71401a737a4371990a17.png)
6. Choose the **Connection alias** from the available Connection Pool list and click **Finish**
![image](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/c/c81e0c40646c5558d4ef9a076171a16a70aa9a45_2_506x500.png)
7. Now click **Recourse Name** option as mentioned in the below screenshot
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/4/4104e1f17f267c65368b7bc95fc4f63361f5a658.png)
8. Then choose the **Query** resource from the list of resources and click **Next**
![image](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/e/e3f2a0feb77a390eae6043e5be227b7787e891b4_2_690x410.png)
9. All the business objects will appear in the next window, here we will choose the **accounts** business object to query the accounts. Choose **accounts** and click **Next**
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/0/089e839daa8c803802af41a551088cb315d6dc63.png)
10. In the next screen, the user will find all the fields list with respect to the **accounts** business object. Here user can choose the fields required to be seen in the response. Example: Choose **name** , **account id** & **$expand** and then click **Finish** & **Save**
Choose **accountid** :
![image](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/c/c3f353da146418f04b2a1007f3c8b04e33242f51_2_690x120.png)
Choose **name** :
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/c/c0b83dae1744be4cb2f90d21b0d3b7386dace4bc.png)
Choose **$expand** : Related entities to be included inline in the response. More information about the **$expand** can be found at [Using $select, $expand, and $value in ASP.NET Web API 2 OData - ASP.NET 4.x | Microsoft Docs](https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/using-select-expand-and-value)
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/d/d8d6afe91db0265c3d12459be68cdddfb28b47d0.png)
11. Now we will run the **queryAccounts** CCS
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/9/9db27dfeab325082d48cc04cbd40dae89a4c4e52.png)
12. The next screen shows all the **request parameters**. First, we will run this service without specifying any parameters, click **OK**
![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/4/4acf4b78186664f21dae2269a631e098aa172acf.png)
13. This service executes successfully, the user will get all the account details present in the tenant with the fields selected in the above step 10
![image](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/7/77c4cce039909f7f9d47d049093053ed26b5c607_2_690x356.png)
14. Now we will query based on the **request parameters**. Rerun this service again, this time we will fetch the information about the particular **accountid** (not all the accounts). Example: Specify the **filter** option
**filter: accountid eq 4ab4a12a-1f3e-e911-a960-000d3a1f716c**
[![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/2/2a165d99150b4931ffc626a5b091e3e74035fe27.png)
**Results:**
![image](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/f/f2202f464d00701b17ba6df9ba225a7e7cce001a_2_690x439.png)

[Read full topic](https://tech.forums.softwareag.com/t/microsoft-dynamics-crm-365-query-operations-with-expand-option/239887/1)