How do I select Dynamics CRM reference attributes? - dynamics-crm

Please read the follows and tell me what I did wrong.
The request I sent:
https://gravityrush.crm5.dynamics.com/api/data/v9.1/accounts?$expand=ownerid/$ref
The response I expected:
"ownerid":{
"#odata.type":"#Microsoft.Dynamics.CRM.systemuser",
"#odata.id":"https://gravityrush.crm5.dynamics.com/api/data/v9.0/systemusers(41041b99-e1ae-46c6-a10c-95ce77fc0b18)"
}
The response I received:
"ownerid":{
"#odata.type":"#Microsoft.Dynamics.CRM.systemuser",
"#odata.id":"https://gravityrush.crm5.dynamics.com/api/data/v9.1/owners()"
}
Thank you.

I think it's possibly a limitation/bug related to this field type.
As you know, the ownerid field can point to a systemuser or team record, and if you take a look at the field definition you'll see that the relationship is actually to an entity called Owner, and that's why you're getting the owners() url:
"#odata.id":"/api/data/v9.1/owners()"
I tried to workaround this using the owninguser and owningteam fields, but it looks like there's an issue there as well because when I added the $ref I started to get nulls values for that field:
GET /api/data/v9.1/accounts?$select=accountid&$expand=owninguser($select=systemuserid)
"owninguser":{
"systemuserid":"f30a6a42-3067-4c78-b348-9cbc56531f5e",
"ownerid":"f30a6a42-3067-4c78-b348-9cbc56531f5e"
}
GET /api/data/v9.1/accounts?$select=accountid&$expand=owninguser/$ref
"owninguser":null
Just to be sure, I tried to do the same for a Customer field (kind of same principle where this field can point to a contact or account record) but I din't found this issue, you can get the reference to the Account/Contact using the following query:
GET /api/data/v9.1/incidents?$select=incidentid&$expand=customerid_account/$ref, customerid_contact/$ref

Try to send API query as below and you shall have the OwnerId
https://orgurl/api/data/v8.2/accounts()?$select=_ownerid_value
You will get OwnerId of each account Record.

Related

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

How to use Get Record to lookup a related record on another object when I don't have the schema Entity Name - Just the LogicalName

All,
I am building a Power Flow. I am returning an object that has a relationship to another entity.
I want to get some values from the related entity.
I am attemping to use the "Get Record" connector. The returning object returns just the logicalEntityName (in this case "opportunities") but Get Record wants an Entity Name that is the Schema Name ("Working Opportunities").
Big Question: What's the secret to use CDS to get information from a related record in another object?
Little Question: How do I do get the Schema Name?
The logical name will be the same as schema name except some casing difference, ie schema name will have camel casing (first letter of first/second word with capitals, you can notice it clearly in custom entity which will have publisher prefix like new_entityname) and logical name will have pascal casing (all lower case).
You can find the details in XrmToolBox metadata browser or in Solution.
In the below snip, (Logical) Name = Opportunity and Schema Name = Opportunity, also Display Name can be anything and can be changed anytime.
Regarding the related entities, you should use List Records: GetItems_V2 and you can use filter by passing parent record to get related child records. Read more
Could you please share flow screenshot and response to help you with your requirement?
As suggested by Arun you could use List Record and filter query to pass parent record id which will be available from dynamic content.
see below link.
https://crmkeeper.com/2019/08/31/cds-list-records-filter-query-using-flow/
Please mark my answer verified if i were helpful

In my query, could I use the result of a parameter to get more info in that query?

Forgive my terribly-worded question but here's some code to explain what I'm trying to do (slug and value are provided outside this query):
const query = `{
post(slug: "${slug}") {
content
createdAt
id <--- I want this id for my reply query
slug
}
reply(replyTo: "id") { <--- The second query in question
content
createdAt
id
slug
}
user(id: "${value}") {
username
}
}`;
I just got started with GraphQL and I'm loving the fact that I can query multiple databases in one go. It'd be great if I could also perform some "queryception" but I'm not sure if this is possible.
When thinking in terms of GraphQL, it's important to remember that each field for a given type is resolved by GraphQL simultaneously.
For example, when your post query returns a Post type, GraphQL will resolve the content and createdAt fields at the same time. Once those fields are resolved, it moved on to the next "level" of the query (for example, if content returned a type instead of a scalar, it would then try to resolve those fields.
Each of your individual queries (post, reply, and user) are actually fields of the Root Query type, and the same logic applies to them as well. That means there's no way to reference the id returned by post within reply -- both queries will be fired off at the same time.
An exception to the above exists in the form of mutations, which are actually resolved sequentially instead of simultaneously. That means, even though you still wouldn't be able to use the result of post as a variable inside your reply query, you could use context to pass the id from one to the other if both were mutations. This, however, is very hackish and requires the client to request the mutations in a specific order.
A more viable solution would be to simply handle this on the client side by breaking it up into two requests, and waiting to fire the second until the first one returns.
Lastly, you may consider reworking your schema to prevent having to have multiple queries in the first place. For example, your Post type could simply have a replies field that would resolve to all replies that correspond with the returned post's id.

How to get 'ownerid' column from CRM database of type `owner` using Web API approach?

I'm using Microsoft dynamics 365 - on premises of my client. Here, I am facing an issue in accessing one of the fields - ownerid of type owner.
I am using Web API approach to access the CRM data. When I hit the query in URL, it brings all the data except ownerid column.
It's field type is: Simple
Has anyone faced the same issue with WebAPI query approach?
URL Query:
https://baseURL/moves?$select=moveid,ownerid,movenumber&$filter=movenumber%20eq%20%27236659%27
Output:
{
"#odata.context":"https://baseURL/$metadata#moves(moveid,ownerid,movenumber)","value":[
{
"#odata.etag":"W/\"37655223\"","moveid":"4583b2fe-83d9-e611-80c7-369e029457bb","movenumber":"236659"
}
]
}
I think ownerid is a lookup, so you need to expand it first by using $expand query parameter, to be included in the response.
https://baseURL/moves?$expand=ownerid&$select=moveid,ownerid,movenumber&$filter=movenumber%20eq%20%27236659%27
Reference: https://learn.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/using-select-expand-and-value

How to create a contact record with customer field set as contact or account

I am trying to create a contact record with its customer set to Account/Contact where customer records are pre-existing.
Here is the request that I am trying.
POST <service>/api/data/v8.0/contacts
{
'lastname':’contact1’,
'parentcustomerid_contact': '/contacts(f797401d-64c9-e711-8125-000d3a22f66f)'
}
I also tried providing full url of the contact record, but that is also not working. Appreciate any help with correct query or any document that I shall go through to get this scenario working.
You have to use like this parentcustomerid_contact#odata.bind to bind single valued navigation properties.
you must use the #odata.bind annotation to set the value of a single-valued navigation property.
Read more

Resources