public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
EntityReference target = (EntityReference)context.InputParameters["Target"];
if (target.LogicalName == "new_mediationsession" || target.LogicalName == "cmu_assignedmediator")
{
Relationship relationShip = (Relationship)context.InputParameters["Relationship"];
EntityReferenceCollection relatedentities = (EntityReferenceCollection)context.InputParameters["RelatedEntities"];
foreach (EntityReference rel in relatedentities)
{
if (rel.LogicalName == "cmu_assignedmediator" && relationShip.SchemaName == "cmu_cmu_assignedmediator_new_mediationsession" && context.MessageName == "Associate")
{
GetMediationSession(rel, service, target, mediator);
}
}
}
}
public void GetMediationSession(EntityReference rel, IOrganizationService service, EntityReference target, Entity mediator)
{
QueryExpression query = new QueryExpression()
{
EntityName = "new_mediationsession",
ColumnSet = new ColumnSet(true),
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "new_mediationsession",
LinkFromAttributeName = "new_mediationsessionid",
LinkToEntityName = "new_new_mediationsession_new_mediator",
LinkToAttributeName = "new_mediationsessionid",
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "new_mediatorid",
Operator = ConditionOperator.Equal,
Values = {rel.Id}
}
}
}
}
}
};
EntityCollection ec = service.RetrieveMultiple(query);
Here Entity 1 is new_mediationsession, Intersection Entity - new_new_mediationsession_new_mediator.
and Entity 2 id is rel.Id which triggered assosciate operation .
Here cmu_assignedmediator is the entity which triggered asssosciate message and has N:N relationship with new_mediationsession.
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
EntityReference target = (EntityReference)context.InputParameters["Target"];
if (target.LogicalName == "new_mediationsession" || target.LogicalName == "cmu_assignedmediator")
{
Relationship relationShip = (Relationship)context.InputParameters["Relationship"];
EntityReferenceCollection relatedentities = (EntityReferenceCollection)context.InputParameters["RelatedEntities"];
foreach (EntityReference rel in relatedentities)
{
if (rel.LogicalName == "cmu_assignedmediator" && relationShip.SchemaName == "cmu_cmu_assignedmediator_new_mediationsession" && context.MessageName == "Associate")
{
GetMediationSession(rel, service, target, mediator);
}
}
}
}
public void GetMediationSession(EntityReference rel, IOrganizationService service, EntityReference target, Entity mediator)
{
QueryExpression query = new QueryExpression()
{
EntityName = "new_mediationsession",
ColumnSet = new ColumnSet(true),
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "new_mediationsession",
LinkFromAttributeName = "new_mediationsessionid",
LinkToEntityName = "new_new_mediationsession_new_mediator",
LinkToAttributeName = "new_mediationsessionid",
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "new_mediatorid",
Operator = ConditionOperator.Equal,
Values = {rel.Id}
}
}
}
}
}
};
EntityCollection ec = service.RetrieveMultiple(query);
Here Entity 1 is new_mediationsession, Intersection Entity - new_new_mediationsession_new_mediator.
and Entity 2 id is rel.Id which triggered assosciate operation .
Here cmu_assignedmediator is the entity which triggered asssosciate message and has N:N relationship with new_mediationsession.
No comments:
Post a Comment