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

Add/Remove Members to Team

Hi all,

Please find the Plugin Code to Add and Remove Members to a Team using C#

//Add Members to Team

public static void AddMembersToTeam(Guid teamId, Guid[] membersId, IOrganizationService service)
        {
            // Create the AddMembersTeamRequest object.
            AddMembersTeamRequest addRequest = new AddMembersTeamRequest();

            // Set the AddMembersTeamRequest TeamID property to the object ID of
            // an existing team.
            addRequest.TeamId = teamId;

            // Set the AddMembersTeamRequest MemberIds property to an
            // array of GUIDs that contains the object IDs of one or more system users.
            addRequest.MemberIds = membersId;

            // Execute the request.
            service.Execute(addRequest);
        }

//RemoveMembers to Team

        public static void RemoveMembersFromTeam(Guid teamId, Guid[] membersId, IOrganizationService service)
        {
            // Create the AddMembersTeamRequest object.
            RemoveMembersTeamRequest addRequest = new RemoveMembersTeamRequest();

            // Set the AddMembersTeamRequest TeamID property to the object ID of
            // an existing team.
            addRequest.TeamId = teamId;

            // Set the AddMembersTeamRequest MemberIds property to an
            // array of GUIDs that contains the object IDs of one or more system users.
            addRequest.MemberIds = membersId;

            // Execute the request.
            service.Execute(addRequest);
        }

Friday, July 24, 2015

Filter Home Page Views using Plugins

Hi all,

As per the CRM, Views we can filtered using Filtering criteria to filter it, some of the conditions we cannot achieve in Filtering Criteria, we can achieve this using Plugins.

Create a Step with the message name as RetrieveMultiple


Copy paste the below code and alter the fields based on your conditon. It will trigger on Page Refresh and View Changes

 if (localContext.PluginExecutionContext.InputParameters.Contains("Query") &&
                        localContext.PluginExecutionContext.InputParameters["Query"] is QueryExpression)
                {

                    QueryExpression query = localContext.PluginExecutionContext.InputParameters["Query"] as QueryExpression;
                    query.ColumnSet.Columns.Add("createdon");
                    query.ColumnSet.Columns.Add("createdby");
                    ConditionExpression condition = new ConditionExpression("name", ConditionOperator.Equal,
                        localContext.PluginExecutionContext.UserId.ToString());
                    ConditionExpression condition1 = new ConditionExpression("createdby", ConditionOperator.Equal,
                       localContext.PluginExecutionContext.UserId.ToString());
                    FilterExpression filter = new FilterExpression();
                    filter.AddCondition(condition);
                    filter.AddCondition(condition1);
                    filter.AddCondition(condition2);
                    query.Criteria.Filters.Add(filter);
                    filter.FilterOperator = LogicalOperator.Or;
                }

Thursday, July 23, 2015

Business Rules with Form Type


Create a Business Rules with Form Type

              --> while Creating a new record Form type wont be available so you can check the created on date to proceed in Business Rules

Here is the rule for create form.

Filter Lookup

Hi All,

We can filter the Lookup based on below code in CRM 2011 but in CRM 2013 and CRM 2013 we cannot achive this

Note: Replace "to" with "field Name"

if (crmForm.all.to!= null) {
            lookuptypeIcons = '/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif';
            lookuptypenames = 'contact:2:Contact,systemuser:8:User';
            lookuptypes = '2,8';

            crmForm.all.to.setAttribute("defaulttype", "2");
            crmForm.all.to.setAttribute("lookuptypes", lookuptypes);
            crmForm.all.to.setAttribute("lookuptypenames", lookuptypenames);
            crmForm.all.to.setAttribute("lookuptypeIcons", lookuptypeIcons);
            Xrm.Page.getControl("to").setDefaultView("A2D479C5-53E3-4C69-ADDD-802327E67A0D"); //GUId for  default View            
        }

we can achive this by using below code

 $("#to").focus(function () {
    var toLookUp = $("img[attrName='to']");
    var lookuptypeIcons = '/_imgs/ico_16_2.gif?ver=828891367:/_imgs/ico_16_8.gif??ver=828891367';
  var lookuptypenames = 'contact:2:Contact,systemuser:8:User';
    lookuptypes = '2,8';
    if (toLookUp.length > 0) {
        toLookUp[0].setAttribute("lookuptypenames", "contact:2:Individual,systemuser:8:User");
        toLookUp[0].setAttribute("lookuptypes", "2,8");
        toLookUp[0].setAttribute("lookuptypeIcons", lookuptypeIcons);
        toLookUp[0].setAttribute("createpermissiondictionary", "contact:true,systemuser:true");
        toLookUp[0].setAttribute("DefaultViewId", "A2D479C5-53E3-4C69-ADDD-802327E67A0D");
        toLookUp[0].setAttribute("defaulttype", 2);
    }
});    

How to Run Microsoft Flow for Every one Month

Introduction: In this Blog we will see how to Run Microsoft Flow for Every one Month. Implementation Steps:   1. Navigate to  https://make.p...