In my application I have a certain entity type selected and retrieve all field attributes of this entity from the EntityDefinitions web API endpoint by expanding Attributes ($expand=Attributes). For a certain attribute of type 'Lookup' (AttributeType) I want to know the type of the related entity. Because the attribute request contains so much data for every attribute, I am filtering the expand by selecting a few properties. Unfortunately it is seems to be not possible to select the Targets property. Therefore, I have to either request all the data (which is slow) or I am filtering and don't know the entity type.
Here is my request which works when Targets is omitted.
`EntityDefinitions?` +
`$filter=EntitySetName eq '${entityTypeName}'&` +
`$select=Attributes&` +
`$expand=Attributes(` +
` $select=DisplayName,LogicalName,Targets` +
`)`
Is it possible to select the Targets property?
Different solution approaches
These approaches come with their own drawbacks in my use case.
- Requesting all
RelationshipDefinitionsdata at once. It contains all the necessary for every entity. The received data is huge and the request take quite a few seconds. Therefore the response is should be cached in the localStorage of the users browser. Filtering the request by only necessary properties seems to be not possible simarly to the EntityDefinitions. - Requesting exact one data record of the selected entity where the particular lookup is not null and including the annotation header, so that the lookuplogical name is present. This has the drawback, that no such record is found in the system. Also feels wrong to request data records instead of MetaData.
Example: account entity, get entity type of primarycontactid lookup field attribute. Url, header and response:
http://SYSTEM_URL/ORGA_NAME/api/data/v8.2/accounts?$filter=primarycontactid ne null&$top=1
'Prefer': `odata.include-annotations="*"`
"[email protected]": "contact",
- Requesting the metadata in C# and invoking the code from JS via a custom action.