Can I use FetchXML to retrieve a list of Entities and a list of Attributes? - dynamics-crm

I want a fetchxml that will return a list of Entities, hopefully with Display name and schema name.
Similarly I would like a fetchxml that will return the attributes for an Entity. Also with Display name and Schema name.
I assume there is a way because tools in the XRMToolBox load dropdowns with those value.

Fetchxml is DML query to retrieve data from backend & cannot be used for metadata retrieval. We have to use Organization service or web api to pull Metadata like Entity & attribute definitions.
SO thread 1 & thread 2 will help you to achieve it.
Other useful links:
Query metadata using the Web API
Retrieve data with queries using SDK assemblies
Use the Organization Service to read and write data or metadata

Related

How to distinguish entities in Dynamics CRM using the web API?

I am using the request to GET "/api/data/v9.0/EntityDefinitions" to list all the entities that are present in Dynamics and get basic information regarding them (EntityMetadata EntityType).
I know that some of the entities are standard, custom, non-createable, non-updateable, etc.
To check if an entity is a custom I can use a field named IsCustom from EntityDefinition and if it is true then the entity is custom. But for non-createable entities and others (I don't know how to call them properly) this approach is not applicable, because there is no such field.
For example, 'activitypointer' supports only GET operation (activitypointer EntityType). Records of this type cannot be created. But from the request above, I cannot get the correct information about that.
Can entities be distinguished?
P.S.: maybe I did something wrong and need to look elsewhere?

How to retrieve field values and its translations from Microsoft dynamics CRM using REST API

I need to retrieve the entities from my CRM site and all the fields associated with that entity. Need to get the translated values as well.
Please provide some queries that will be helpful in this case
I tried with below queries, but this could not fetch all the values.
..../api/data/v9.1/EntityDefinitions(LogicalName='account')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet
..../api/data/v9.1/EntityDefinitions(LogicalName='account')/Attributes
..../api/data/v9.1/GlobalOptionSetDefinitions
You can retrieve CRM entities by calling:
[Organization URI]/api/data/v9.1/
In order to get an entity's attributes you can call:
[Organization URI]/api/data/v9.1/EntityDefinitions(LogicalName='[Entity name (ex: account)]')/Attributes
For attribute translation, navigate to 'DisplayName' you will find 'LocalizedLabels'.
For more information you can check this url:
https://learn.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-metadata-web-api

Dynamics 365 OData getting 1:N linked entities

I have entities of type account which when I look at it in Dyn365 it has a section containing a list view of related entities. How do i get these related entities from the OData API?
I can query api/data/v9.1/account but the related entities do not appear anywhere in the resulting json.
If I do the same for the related entities the account do not appear anywhere. How do I get the link between these two types of entities? using the OData API.
I've tried things like /accounts?$expand=contact($select=foo) but it just says contact property do not exist on the account entity, which is correct. But contact is not a property its an entity type.
Solution is to use the following url to get the names of all relationships.
https://<company>.crm.dynamics.com/api/data/v9.1/RelationshipDefinitions?$select=SchemaName
Result is an array of the following rows for each relationship.
{"#odata.type":"#Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata","SchemaName":"aaa_bbb","MetadataId":"<guid>"},
Then use those names, specifically the SchemaName property in the $expand query parameter.
https://crmdev.crm.dynamics.com/api/data/v9.1/accounts?
$select=<whatever>&
$expand=aaa_bbb($select=<properties from linked entity>)
To figure out what relationship actually do what you need, you need to read in more then just the SchemaName if you can't guess what is what, or look it up in Dynamics through the GUI if you know how and have access. I don't.
The RelationshipDefinition contains other properties like ReferencedEntity ReferencingEntity that can be used to determine if you got the right relationship.
Probably, this is what you are looking for. The relationship for 1:N between account and contact is contact_customer_accounts
All accounts with its related contacts:
https://crmdev.crm.dynamics.com/api/data/v9.1/accounts?$select=name&$expand=contact_customer_accounts($select=fullname)
Particular account with related contacts:
https://crmdev.crm.dynamics.com/api/data/v9.1/accounts(73C84814-729B-EA11-A811-000D3A370DB6)?$select=name&$expand=contact_customer_accounts($select=fullname)

dynamics crm 365 plugin apply QueryExpression to custom list of entities

In my plugin, I have a list of entities. I would like to apply the query expression that is passed in the input parameters
QueryExpression query = PluginExecutionContext.InputParameters["Query"];
to a custom list of type entity.
List<Entity> myList;
The entities in the list match the same attributes as the entities used in the plugin context. Is there a way to apply a QueryExpression to a list of entities, or convert a QueryExpression to linq?
QueryExpression is really just a wrapper around FetchXML, which is just an XML schema for queries in Dynamics CRM. If you want to pass in a query as a parameter to a plugin, you could set up an custom entity call "query" or something to that effect and add a field of type textarea to that custom entity called "fetchxml". Then set up the input parameter of your plugin to accept a record of that custom entity instead of a text parameter. this has the added benefit of allowing you to more easily edit the input parameters of the plugin.
Of course, you could always just put the raw fetchXML into the parameter as text, but I can tell you from experience that this will come back to bite you as it is extremely hard to maintain because any changes elsewhere in the system could completely trash your plugin.
If you want to know more about how to get the fetchXML for a certain query or have any other questions, just shoot me a comment.
Is there a way to apply a QueryExpression to a list of entities
Answer is No.
QueryExpression & FetchXML is native of Dynamics CRM, it can be used against CRM service (Database) only. I assume this plugin is on Retrieve message and you are trying to use the system's query expression from that Retrieve service call against your own dataset of entity (List<Entity>). But why?
, or convert a QueryExpression to linq?
No. I know the reverse is possible.

Odata service for two tables and how to make a master table using both tables in UI5

I want to create an OData service to fetch details from two tables of SAP and fit it using Master detail template in UI5. The first table contains only the product Id and description , while the second table contains the Product Id and product details like manufacturer address,cost , exp date etc
Currently two RFC are created writing the SELECT query on the tables to generate OData service from RFC. Shall i create One Entity set and use both RFC from Read and Query each at Map to Data Source ? or create two entity sets to map one RFC for each Entity set ?
How should be the Odata service query look to develop a master detail application in ui5 fetching data from two tables ? As well as how will make a local master table in UI5 using both table which are fetched.
Well, it depends :)
It looks like you have a 1:1 association between the product header and the details.
So you could model header and details as separate entities and define a 1:1 association between them or you could simplify you model and merge both header and detail attributes into one entity. With the information i have, i would prefer the single entity. You can use ODatas $select parameter to request only specific properties. Your DPC implementation could make use of $select and call only the header RFC if only header fields are requested.
I'm not shure if the master detail template can be used with 1:1 associations. Normally they are used with 1:n as the detail page displays a list of detail items. But you can of course leave the details unbounded in the wizard and bind additional fields later in the object header of the detail page.

Resources