My Photo

Microsoft Dynamics 365

Official Blog for Microsoft Dynamics Functional and Technical Solutions....
Browsing Category " PLUGIN "

Get Plugin Registration tool and assemblies from NuGet Packages for Dynamics 365 , v9.0

With the release of Dynamics 365 (online), version 9.0, there are a lot of changes in our developer documentation:
No more monolithic SDK download : Getting the assemblies and tools you need
SDK assemblies and tools will be distributed only via NuGet. We will provide a script that will allow you to download the assemblies and tools from NuGet.

You can follow below steps to download Nuget Packages using Visual studio

Step 1 Right Click on to your visual studio project and click on to manage NuGet Packages


Step 2 Search for "Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool" and click on install


Click on I accept


Step 3 Navigate to the package directory of that project


Step 4 Search the folder Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.X.0.0.X



Done!! now you will be having your latest Plugin registration Tool

Sample PRT Reference for quick start  : Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.9.0.0.7

In the same way you can download any of the NuGet assemblies and tools

Hope it helps !!

Happy CRMing


SOURCE : mscrm.com

Create Your First Plugin Dynamics MS CRM

For your first Plugin we will take a test scenario - on create of contact record our plugin will forcefully update its email address to "testemail@gmail.com" and to achieve this you just need to follow the below steps.

There are two parts to successfully run a plugin in MSCRM

1) Create Your Plugin
2) Resister your plugin

Plugin Creation

Step 1 - Open Visual studio


Step 2 - Go to File - New - and Click on Project


Step 3 - A dialogue will appear, from left navigation panel select Class Library template in Visual C#  and Enter Project and Solution name and hit on OK Button


Step 4 - Visual studio will create and open a blank class library template.Right Click on Project and click on Add References option


Step 5 - Reference Manager dialogue will open.From left navigation panel go to Assemblies - Framework then select two references and click on OK button
1)System.Runtime.Serialization
2) System.ServiceModel


Step 6 -  Right Click on Project and again click on Add References option, then in Reference Manager dialogue from left navigation panel go to Browse - Click on Browse button then select two references
1)System.Runtime.Serialization
2) System.ServiceModel



Step 7 -  After Click on Browse button go to your sdk (downloaded from prerequisites) - bin, then select the following dlls files and click on add and then OK button
1) miscrosoft.xrm.client.dll
2) Microsoft.Xrm.Sdk.dll


Step 8 -  Open the class named Class.cs from solution explorer and modify the below code in it.
If your namespace name and class name is different then remember to verify and update it.

Code Snippet : 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;

namespace My_First_Plugin
{
    public class Class1 : IPlugin     //{inherit the class Iplugin in your class}
    {
        public void Execute(IServiceProvider serviceProvider)        //{add the execute method}
        {
            // create context , service factory and service objects
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            //to enter  value in Email field in contact entity

            //create an object of predefined class Entity and pass entity name as its parameter
            
            Entity Object = new Entity("contact");   // in place of contact you can write schema name of entity on which you want to preform operations

            Object.Attributes.Add("emailaddress1", "testemail@gmail.com");  //emailaddress1 is the schema name of the Email field in contact entity
             //testemail@gmail.com is the value

            //to update the record service.Update(object of the entity)
            service.Update(Object);

        }
    }
}

After updating your code your code will look like this 


Step 9 -  Right click on Project and click on Properties


Step 10 -  Now, we have to create a key. Go to Signing - select the checkbox "Sign the assembly" and click on <New..> option 


Step 11 -  Enter any name you want for your Key and click on OK button


Step 12 -  Click on Save Button


Step 13 - Go to BUILD from ribbon menu and select Build Solution option




Will Update this thread Soon 


Happy Coding 😊


Get / Retrieve all Entity Metadata from an organization in MSCRM 2011, 2013 ,2015 usin C#

Below Code Retrieve all entities , who's Responce can be used to bind entities to drop down or grid etc .




 RetrieveAllEntitiesRequest req = new RetrieveAllEntitiesRequest();
            req.EntityFilters = EntityFilters.Entity;

            RetrieveAllEntitiesResponse resp = (RetrieveAllEntitiesResponse)service.Execute(req);

            foreach (var entity in resp.EntityMetadata)
            {
                //bind it with dropdown ETC
                entities.Items.Add(entity.LogicalName);


            }

Hope This Helped You Thanks For the Support , If Any query or suggestion , please comment below



SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

GET AND SET VALUES FROM ONE ENTITY TO ANOTHER ENTITY USING PLUGIN IN MSCRM 2011 , 2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace elite_employee
{
    public class Class1 : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)
             serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory =

GET AND SET LOOK VALUE FROM ONE ENTITY TO ANOTHER ENTITY USING PLUGIN MS CRM 2011 , 2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace elite_employee
{
public class Class1:IPlugin
{
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);
new_attendee obj = (new_attendee)service.Retrieve(new_attendee.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));
if (obj.new_AttendeeName != null)
{
Guid emp = obj.new_AttendeeName.Id;
new_employee employee = (new_employee)service.Retrieve(new_employee.EntityLogicalName, emp, new ColumnSet(true));
Guid desig = employee.new_Designation.Id;
Guid dep = employee.new_Department.Id;
Guid manag = employee.new_ManagerId.Id;
EntityReference reff1 = new EntityReference(new_department.EntityLogicalName, dep);
EntityReference reff = new EntityReference(new_designation.EntityLogicalName, desig);
EntityReference reff2 = new EntityReference(new_employee.EntityLogicalName, manag);
obj.new_Designation = reff;
obj.new_Department = reff1;
obj.new_Manager = reff2;
obj.new_AttendeeCode = employee.new_EmployeeCode;
service.Update(obj);
}
}
}
}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012