I am trying to query product related information in a Dynamics 365 tenant (Version 9.2.22101.170) and with Version 9.0.2.46 of the Microsoft.CrmSdk. Mostly I am interested in querying products by the product number to retrieve price information, but later on, I would introduce more parameters. The below is one of the many methods I've tried (I am aware I am projecting only the name for the time being, eventually I would require price information etc):
var cols = new ColumnSet(new String[] { "name" });
QueryByAttribute query = new QueryByAttribute("product");
query.ColumnSet = cols;
query.Attributes.AddRange("productnumber");
query.Values.AddRange("100002");
var results = service.RetrieveMultiple(query);
if (results != null)
{
var entities = results.Entities.ToList();
if (entities != null)
{
var productEnt = (Product)entities.FirstOrDefault();
Console.WriteLine(productEnt.Name);
}
}
This is the error message returned, on the RetrieveMultiple call:
The entity with a name = 'product' with namemapping = 'Logical' was not found in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=8343791, MinActiveRowVersion=8343791
The same message is returned when calling any other method. It's clear that the issue is not the query, or the columns being returned but the "product".
Sure enough, I am using the below method to get the list of entity names, and the word "Product" does not show up. I think this explains the error message.
public static EntityMetadata[] GetEntities(IOrganizationService organizationService)
{
Dictionary<string, string> attributesData = new Dictionary<string, string>();
RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
metaDataRequest.EntityFilters = EntityFilters.Entity;
// Execute the request.
metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest);
var entities = metaDataResponse.EntityMetadata;
return entities;
}
Is this a permission issue? Do I need to do some extra loading prior to the query? How do you query product/pricing related information in a Dynamics 365 tenant?
I tried searching for related information online, but I was surprised to practically find almost nothing related to Products.