The plugin is registered in Pre-Operation stage on the Task entity and uses early-bound entity classes.
However it is trivial reuse the same logic on another type of entity, use late-bound entity classes, or operate on other type of assignee.
protected void
ExecutePreTaskAssign(LocalPluginContext
localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context =
localContext.PluginExecutionContext;
IOrganizationService service =
localContext.OrganizationService;
try
{
//Check if context contains the "Target"
parameter and that it
is an EntityReference
is an EntityReference
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is EntityReference)
context.InputParameters["Target"] is EntityReference)
{
EntityReference targetEntity =
(EntityReference)context.InputParameters["Target"];
//Check if the entity type is Task
if (targetEntity.LogicalName != "task")
{
return; }
//Check if context contains the "Assignee"
parameter
if (context.InputParameters.Contains("Assignee"))
{
EntityReference assigneeRef =
(EntityReference)context.InputParameters["Assignee"];
//Check if the "Assignee" is a team
if (assigneeRef.LogicalName == "team")
{
Team team;
//Retrieve
the team with all properties
team = service.Retrieve(assigneeRef.LogicalName,
assigneeRef.Id, new ColumnSet(true)).ToEntity<Team>();
assigneeRef.Id, new ColumnSet(true)).ToEntity<Team>();
//Put your logic here based on the retrieved
Team informations
}
}
}
}
catch (Exception
e)
{
throw new InvalidPluginExecutionException("An error occured for
Assign plugin " + e.Message + e.InnerException);
Assign plugin " + e.Message + e.InnerException);
}
}
Rate this posting:
{[['']]}
No comments:
Post a Comment