Hi
I'm new to CRM programming but need to query an entity to get certain values,
then use those values to pull data from a 2nd entity which will populate a dropdown list.
So... get all accountid's where marketid = "e694b716-1375-e611-80cf-ba308e764b3f" from market_account entity.
Then
Get all accounts (name & accountid) from "account" entity with the accountid's from above?
:( Thanks in advance
*This post is locked for comments
I have the same question (0)Hi Stuie,
You can use the link entity to provide the relationship between the account entity and the related entity. See sample code that I attached below. You can also use advanced find and download the FetchXml query and use that to get your results:
private EntityCollection RetrieveAccounts(Guid accountId) { EntityCollection rc = new EntityCollection(); QueryExpression query = new QueryExpression() { EntityName = "account", ColumnSet = new ColumnSet(new string[] { "accountid", "accountnumber", "name" }), LinkEntities = { new LinkEntity() { LinkToEntityName = "market_account", LinkToAttributeName = "accountid", // Name or record in N<->N relationship LinkFromEntityName = "account", LinkFromAttributeName = "accountid", LinkCriteria = { Conditions = { new ConditionExpression("accountid", ConditionOperator.Equal, accountId) } } } } }; try { rc = service.RetrieveMultiple(query); return rc; } catch (FaultException<OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException("An error occurred in the plug-in (RetrieveAccounts: " + accountId.ToString() + ").", ex); } }
If you use the Fetch Xml to retrieve your results, you can use the following code:
EntityCollection rc = OrganizationService.RetrieveMultiple(new FetchExpression(fetchXml.ToString()));
Community Member
2
Christoph Pock
1