Monday, July 27, 2015

Assign Team in CRM Plugin

Hi All,

Please find the Code for the Assign Team Login in C#

SnapShot:



Plugin :

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
        if (context.InputParameters.Contains("Target") && 
                     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>();

                    //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);
    }
}

No comments:

Post a Comment

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...