Posts

Showing posts with the label CRM 2016

How to bind Dynamics CRM data to dropdown using JavaScript/ HTML?

Image
In this blog, I 'll show how we can create a dropdown and bind it with value from Entity record values e.g we need to show all On-Demand process inside an entity as a dropdown list. So for this I have used 2 methods: ODATA and WebAPI call.. For Users using older version of CRM can use ODATA method. In this below example I am binding all system view in the dropdown inside an HTML web resource. Copy and paste code as below: 1. ODATA Method: <head>     <script type="text/javascript" src="/_common/ClientGlobalContext.js.aspx"></script> </head> <body style="overflow-wrap: break-word; height: 24px; word-wrap: break-word;">     <select id="viewdropdown" onchange="GetSelectedviewValue(this)" style="height:24px; width:495px; margin-left:16px">         <option selected="" value="Loading...">Loading...</option>     </select>     <script> ...

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                 {       ...

Validate Input Phone Number in Microsoft Dynamics CRM using JavaScript

Sometime we get requirement to validate a phone number like to check only numeric value allowed with all round bracket and '+' sign etc in the number. So below is a basic JavaScript fucntion which validates a phone number like: (022)6655-7878 or +91-7878787878 or +44-6756-6767-4234 and so on function CheckPhoneNoFormat(context) {     var oField = context.getEventSource().getValue();     if (typeof (oField) != "undefined" && oField != null) {         try {             var telnum = oField;             // Convert into a string and check that we were provided with something             var telnum = telnum + " ";             if (telnum.length == 1) {                 telNumberErrorNo = 1;                 return false    ...

How to Set field values in CRM through parameters passed to a new form using JavaScript

Image
In this blog I am showing how we can add default values to the new form when open new form. You can set default values for new records created by users by specifying attribute values in the URL that is used to open the form. For this you need to add a Button placed on the form(Existing Record) and on click of this button we'll copy data to the new form from the existing record. In this example I placed a button of account entity form which is enable only if record exists and on click of this a new form opens with few values copied to new form using parameter passed in URL. Add code as shown below function GetIdFromLookup(lkpFieldSchemaName) {     var lkpField = null;     var sGuid = null;     lkpField = Xrm.Page.data.entity.attributes.get(lkpFieldSchemaName);     if (lkpField != null && lkpField.getValue() != null)         sGuid = lkpField.getValue()[0].id;     return sGuid; } function ...

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...

How to add custom filter lookup field based on OptionSet field selection in Dynamics CRM.

Image
In this blog I am going to show how we can filter records based on the selected option set value. For this example I have created an entity and placed 2 fields mainly, One is Option set Field for Region/ Divison and another is Lookup filed of State. So when user will select the region the lookup values will show only filtered records based on the region, copy and paste the code below in your form option set OnChange event which will filter record of lookup. function FilterPackagesLookup() {     try {         preFilterLookup();     } catch (e) {         ShowCatchMessage(e.message);     } } function preFilterLookup() {     try {         if (Xrm.Page.ui.controls.get("new_state") != "undefined" && Xrm.Page.ui.controls.get("new_state") != null) {             Xrm.Page.getControl("new_state").addPreSearch(function () {     ...
go to top image