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

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

Related

Microsoft Dynamics API - Getting Fields from Entity with Navigation

I am trying to get the field list from an entity, in example contact, I have successfully done it doing a Request to:
EntityDefinitions(LogicalName='contact')/Attributes/Microsoft.Dynamics.CRM.AttributeMetadata
But now I need to get the Navigation Properties defined on this entity, I have found information on how to get Navigation Properties when querying a specific record by id, but in this case I need it when getting the field list.
Thanks in advance for your help
Referring the docs: https://learn.microsoft.com/en-us/powerapps/developer/data-platform/webapi/query-metadata-web-api
You already have the Lookup attributes, AttributeMetadata has everything.
If you want to only read the metadata of lookups, change the type to LookupAttributeMetadata.
EntityDefinitions(LogicalName='contact')/Attributes/Microsoft.Dynamics.CRM.LookupAttributeMetadata
To obtain relationships info alongside the columns list then an additional query is required, RelationshipDefinitions:
/RelationshipDefinitions/Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata
/RelationshipDefinitions/Microsoft.Dynamics.CRM.ManyToManyRelationshipMetadata
filter on ReferencedEntity / ReferencingEntity to limit the results
/RelationshipDefinitions/Microsoft.Dynamics.CRM.ManyToManyRelationshipMetadata
filter on Entity1LogicalName / Entity2LogicalName / IntersectEntityName

Filtering across multiple Dynamics entities in Common Data Service

I'm trying to query our Dynamics 365 CRM through the Common Data Service / Microsoft Dataverse. I can manage this when I need to just filter on fields that exist within the entity type I'm searching. But I also need to filter on a different linked entity.
So far I can query on the contact entity just fine:
var contacts = svc.Get("contacts?" +
"$select=firstname,lastname,address1_name,address1_line1," +
"address1_postalcode,emailaddress1,statecode,_parentcustomerid_value&" +
$"$filter=contains(firstname,'{firstName}') and " +
$"contains(lastname, '{lastName}')"
, formattedValueHeaders);
And this returns a list of contacts which match the filter.
However, I also need to filter on the Account Name that the contact is linked to. If I had the AccountId value then I could do this by adding $"contains(_parentcustomerid_value, '{accountId}')" to the filter. But I can't use this as the input data I'm receiving to query on is the name of the account and not an Id value.
Any ideas on how to do this?
Currently, the only way I can see is to use my existing query, then to loop through each contact and check the returned account name in the response, and if this matches then in effect I've filtered it. But I would prefer to be able to have the whole filter all in a single query.
You can use this to filter based on lookup field name value.
https://devorg.crm.dynamics.com/api/data/v9.1/contacts?$filter=parentcustomerid_account/name eq 'test'

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 populate look up field based on text field - Dynamics 365

I am trying to populate contact field (Potential Customer) based on text field (Email Address) set. To bear in mind, it should be unique based on the customer record.
Condition is if Email address field is set, look up field (Potential Customer) value should be fetched based on the Email address field.
Wherever you are trying to fill that contact lookup from (plugin, form script, console job, web app, ETL, MS Flow, etc), you have to fetch the contact by filtering the email value and set it in lookup entity reference.
You can use web api or fetchxml to achieve that. Here is how it should look like.
https://crmdev.crm.dynamics.com/api/data/v9.0/contacts?$select=fullname&$filter=emailaddress1 eq 'test#gmail.com'
C# example
Javascript example
Once you fetch the lookup field based on email address using web api which is suggested by Arun. To set lookup field on form using javascript see below article.
https://xrmdynamicscrm.wordpress.com/2020/06/17/dynamics-crm-365-set-lookup-regarding-field-while-using-xrm-navigation-openform-formparameters/
Please mark my answer verified if i were helpful

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

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

Resources