Using QueryExpression get the Link Entity details in D365
public static void Main()
{
EntityCollection salesOrderCollection = this.GetAccounts(customerId, salesOrderCreationDate);
}
public EntityCollection GetAccounts(string customerId, DateTime AccountBaseCreationDate)
{
QueryExpression ContactItemQuery = new QueryExpression(AccountBase.LogicalName);
// Add Condition to Customer.
ContactItemQuery.Criteria.AddCondition(AccountBase.Id, ConditionOperator.Equal, customerId);
FilterExpression mainFilter = new FilterExpression(LogicalOperator.And);
mainFilter.AddCondition(AccountBase.CreatedOn, ConditionOperator.GreaterThan, AccountBaseCreationDate);
FilterExpression statusCodeFilter = new FilterExpression(LogicalOperator.Or);
statusCodeFilter.AddCondition(AccountBase.Status, ConditionOperator.Equal, (int)AccountBase.AccountStatus.Submitted);
statusCodeFilter.AddCondition(AccountBase.Status, ConditionOperator.Equal, (int)AccountBase.AccountStatus.Fulfilled);
statusCodeFilter.AddCondition(AccountBase.Status, ConditionOperator.Equal, (int)AccountBase.AccountStatus.Invoiced);
mainFilter.AddFilter(statusCodeFilter);
ContactItemQuery.Criteria.AddFilter(mainFilter)
// Add Link to Price List Entity.
LinkEntity Contact = new LinkEntity(
AccountBase.LogicalName,
ContactBase.LogicalName,
AccountBase.Contact,
ContactBase.Id,
JoinOperator.Inner);
// Add Link to ContactItems Entity.
LinkEntity ContactItems = new LinkEntity(
ContactBase.LogicalName,
ContactItemsBase.LogicalName,
ContactBase.Id,
ContactItemsBase.Contact,
JoinOperator.Inner);
ContactItems.EntityAlias = "pi";
ContactItems.Columns.AddColumns(ContactItemsBase.Product, ContactItemsBase.Unit);
Contact.LinkEntities.Add(ContactItems);
// Add Link to Unit Entity.
LinkEntity unit = new LinkEntity(
ContactItemsBase.LogicalName,
UnitBase.LogicalName,
ContactItemsBase.Unit,
UnitBase.Id,
JoinOperator.Inner);
unit.LinkCriteria.AddCondition(UnitBase.UnitType, ConditionOperator.Equal, (int)UnitBase.UnitTypeValue.Case);
ContactItems.LinkEntities.Add(unit);
ContactItemQuery.LinkEntities.Add(Contact);
// Execute Query.
return this.organizationService.RetrieveMultiple(ContactItemQuery);
}
Comments
Post a Comment