Posts

Showing posts with the label Plugin

How to Write a Plugin when a Case is resolved with use Email Template in C#

In this blog, I am going to explain how we can fire a plugin on Resolved Case. Additionally I have added methods which shows how we can use Email Template too. Follwing points is important when working on resolved case plugin: 1. To fire a plugin when an incident is resolved we need to register the plugin in "Close" message for the incident entity. 2. In Input parameters of the context we need to check for IncidentResolution (this entity holds information of case being closed). Put below codes inside your Plugin, In my sample code I am creating an email activity after case gets resolved.         public class IncidentPostCloseHandler : IPlugin         {             public void Execute(IServiceProvider serviceProvider)             {                 try                 {       ...

How to generate PDF/ xls report from .rdlc without using Reporting services in c#.

In this blog, I am going to show how to create a Report dynamically using a DataSet in Report document (*.rdlc). and show the report without much effort. Step 1: Create a Report(.rldc) using SSRS or any other tool. Add appropriate  DataSet and DataSource and with required columns create a table and Bind DataColumns. Once Report created build and Goto Code behind solution. Step 2: Now in the Code behind, add the following codes and required references. Note: I have added just 3 fields report and the same field should be used in code behind also with exact DataSet name as it is in Report. Currently DataSet has hardcode value which you can replace with fetched value from Database. using System.Collections.Generic; using Microsoft.Reporting.WebForms;         #region ReportGenerateFromRDLFile         public static void RenderReport()         {             string sReportPath ...

How to create Email activity with dynamically retreived data from Dynamics CRM through Plugin C#

Image
In this blog, I am going to show how we can add dynamically retreived data from CRM in a table and show this data inside a table within the Email body. Apart from adding dynamic data in a table into Email body I have also added code for showing Image which we have saved in web resources inside CRM. In short this blog covers below point: Adding Image from Web Resources Creating HTML formatted table from DataTable Converting EntityCollection into DataTable Showing dynamic data in Email body description  1. First of all below required namespaces in your code(Add required references)  using Microsoft.Crm.Sdk.Messages;  using Microsoft.Xrm.Sdk;  using Microsoft.Xrm.Sdk.Query;  using System;  using System.Collections.Generic;  using System.Data;  using System.Linq;  2. Now Goto your CRM Settings, Add a web resource of type Image.  3. Now Add below codes in the Execute method of your plugin as it is:  public class Cla...

Modify Lead Qualification process in Dynamics CRM using C#: How to prevent Opportunity/ Account Creation and Refresh Lead Page On Lead Qualify

One condition on Lead Qualify could be like: If we don't want to create Opportunit/ Account or Contact on Lead Qualification that heppens by default. So for this secnario Below is the code which is required to stop creation of Opportunity/ Account on Qualifying Lead. Note: Register Plugin on "QualifyLead" message and Pre-Operation public void Execute(IServiceProvider serviceProvider)        {        AvoidOpportunityCreationOnLeadQualify(serviceProvider);      }        private void AvoidOpportunityCreationOnLeadQualify(IServiceProvider serviceProvider)      {        IPluginExecutionContext contextPlugin = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));        IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));     ...

How to Get the records when Lead is Qualified in Microsoft Dynamics CRM using Plugin C#

Image
In this blog I am going to explain and show an example when a lead is Qualified then how we can get the new records or we can update records in newly created record when Lead status is Qualified. 1. Register your created plugin in "QualifyLead" message and On Post-Operation to get the records when lead is Qualified. :: 2. Here in this example I am setting up a Lookup field value in newly created Opportunity when lead is Qualified. Just type the code as below and register as said in Step 1.       IOrganizationService serviceDefaultUser = null;             IPluginExecutionContext contextPlugin = GetContext(serviceProvider);             serviceDefaultUser = GetServiceObject(serviceProvider, contextPlugin);             // Get the qualified lead.             EntityReference leadid = (EntityReference)context.InputParameters["LeadId"];  ...

Manipulate date fields by adding or subtacting days to a DateTime fields in Microsoft Dynamics CRM using workflow activity

Image
Source: ManipulationLibrary In this blog I am going to explain how to manipulate a date field in Dynamics CRM 2013 using plugin workflow activity. This workflow allows days to be added/ subtracted to date field in CRM. 1. For creating this Workflow activity using plugin Open Visual studio and just proceed similarly as you do for creating any plugin i.e add necessary references, etc. 2. Now add a class file for and name it accordingly and add below code for Adding days to date:: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Activities; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; namespace AddSubtractDate {     public sealed class AddDays : CodeActivity     {         protected override void Execute(CodeActivityContext executionContext)         {             var result =...

Send Email(With Image) from Plugin on Post Operation of an entity in Microsoft Dynamics CRM

Image
In this blog I am going to explain how to send Email to User in CRM from Plugin. 1. Add image url properly if you want to add image inside mail body like below::      string crmModule = "<html> <img  src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQZmbAJpYMlYRlzgUZ3OluhNEMTfSj-7hyNwapoZ0IGk1SrhBkZEn8C6Ky8y19xS72g388EtC0lIVtsZlOcbq_Ok7wrcav5sishe7DFSupFQcnG6sXXj0P803MPOpk_xcyFKWR8U0GqC7R/s1600/1032510.png'  width='150' height='150'></html>";    Or,   Alternatively, You can also Display Image Which are Created in CRM as Web Resource. Upload your image as Web resource in Crm and Copy paste the URl available in webresource string as I did below.      string webresource = "<html> <img  src='~/WebResources/new_Crm'  width='205' height='150'></html>"; 2. Add necessary referances to your solution. 3. Now, add code like below for sending Email on Post Creation of...
go to top image