Posts

Showing posts with the label CRM 2013

How to update related entity records in Dynamics CRM using javascript

In this blog, I am going to show how we can update a related entity record through JScript in DYnamics CRM either REST or OData way. First of all I'll show update data using REST Query in Method 1 and then using OData query in method 2. function btnUpdateOnClick() {     try {         var selectedRows = Xrm.Page.getControl("SubGridName").getGrid().getSelectedRows();         selectedRows.forEach(function (selectedRow, i) {             var s = selectedRow.getData().getEntity().getEntityReference();             var selectedRowGuid = s.id;             var selectedRowName = s.name;             var selectedRowEntityName = s.entityType;             UpdateAccount(selectedRowGuid, selectedRowName, selectedRowEntityName);         });     }   ...

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

How to retreive CRM records from an Entity using Fetch XML in Dynamics CRM and show on Grid view using c#. How to Bulk delete records from CRM using c#

Image
In this blog I am going to explain how we could retrive/ delete all records from an entity in CRM using C#. For this demo I have taken a windows application, check the below steps and use the code as it is. This code also includes code how we could show Entity data in Gridview. 1. First of all take two different buttons. First button for retreiving records and 2nd button is for deleting records from an entity in CRM. 2. Place a Gridview control too in your form. 3. Now place code as below on Browse, Bulk_Upload button::         OrganizationService _orgservice = new OrganizationService(CrmConnection.Parse("Url=https://yourSolution.crm5.dynamics.com; Username=admin@yourSolution.onmicrosoft.com; Password=pass@word1;"));                   //Retrive All records from an Entity in CRM using ExecuteMultipleRequest         private void btnRtvMultiple_Click(object sender, EventArgs e)   ...

Bulk upload data in Microsoft Dynamics CRM from Excel using c#, How to Import data from Excel in C#

Image
In this blog I am going to explain how we could upload bulk data in CRM from Excel sheet using C#. For this demo I have taken a windows application, check the below steps and use the code as it is. This code also includes code how we could import Excel data. 1. First of all take a textbox and two different buttons. textbox for showing teh selected file path and first button for Browsing file and 2nd button is for uploading Data in CRM. 2. Place a OpenFileDialog control too in your form. 3. Now place code as below on Browse, Bulk_Upload button:: OrganizationServiceProxy _orgservice = CreateCrmServiceObject();               private void btnBrowse_Click(object sender, EventArgs e)         {             DialogResult fd = openFileDialog1.ShowDialog();             if (fd == DialogResult.OK)             {     ...

Activate/ Deactivate a record using C# in Dynamics CRM 2011/ 2013/ 2015

In this blog I am going to show how we could Activate/ Deactivate a record in Dynamics CRM using c#.  For this we cannot simply activate or deactivate records by simply setting statecode and statuscode in the early bound entity records. To do this, we must use SetStateRequest and SetStateResponse from Microsoft.Crm.Sdk.Proxy assembly. Add all required updated dll referances in your project.                 Below is the methods separately for Activating & Deactivating a record:: public static void DeactivateRecord (Guid recordId, OrganizationServiceProxy organizationService)         {             var EntityName = organizationService.Retrieve("EntityName", recordId, new ColumnSet(new[] { "statecode", "statuscode" }));             try             {                 if (EntityName != ...

Create WCF service and use it to retreive data from Dynamics CRM

Image
1. Open Visual Studio and Select WCF service application. 2. Open IService1.cs and add following code:: namespace WcfServiceCRM {     // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.     [ServiceContract]     public interface IService1     {         [OperationContract]         Account[] getAccountDetails();         // TODO: Add your service operations here     }     // Use a data contract as illustrated in the sample below to add composite types to service operations.     [DataContract]     public class Account     {         string fullname;         string comp...

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

ConditionExpression operators and aggregation used in FetchXML while using c# for Microsoft Dynamics CRM 2013

This blog contains the whole list of COndition operators used in FetchXMl and the aggregation used in FetchXML while using C# Source: MSDN Here is a list of all ConditionalOPerator and the second table contains the list of aggregation used in FetchXML:: ConditionOperator FetchXML Operator Description BeginsWith like The string occurs at the beginning of another string. Between between The value is between two values. Contains like The string contains another string. DoesNotBeginWith not-like The string does not begin with another string. DoesNotContain not-like The string does not contain another string. DoesNotEndWith not-like The string does not end with another string. EndsWith like The string ends with another string. Equal eq The values are compared for equality. EqualBusinessId eq-businessid The value is equal to the specified business ID. EqualUserId eq-userid The value is equal to the specified user ID. EqualUserTe...

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

Connect to Microsoft Dynamics CRM 2013 online using C#

In this blog, I am going to explain how to create connection with Online Microsoft Dynamics CRM and how to fetch data of CRM using C#. Fetch records from online crm entity using c#. First of all add required references and add few important namespaces : using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Client.Services; using Microsoft.Xrm.Client; using Microsoft.Xrm.Sdk.Messages; Now, for creating connection with Online dynamics CRM 2013, add below code inside your class with your URL, UserName and Password of your Online Dynamics CRM . OrganizationService _orgservice = new OrganizationService(CrmConnection.Parse("Url=https://YourURLname.crmX.dynamics.com; Username=user.name@YourSolName.onmicrosoft.com; Password=YourPassword;")); Now, for retrieving records from your online CRM for any entity get the fetchXML by using AdvancedFind and use that...

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

In this blog I have given a list of all StateCode and StatusCode of useful entities. Please refer MSDN for more details for any doubt if you have regarding any thing. I also have collected this through MSDN The following table shows default Microsoft CRM values for StateCode and StatusCode. Each StateCode has its own default StatusCode value. For example, if a Product StateCode is 0 (Active), the default StatusCode is 1 (Active(default)). If the Product StateCode is 1 (InActive), the default StatusCode is 2 (Inactive(default)). Microsoft CRM only accepts StatusCodes that are valid for a particular StateCode. Entity Status (statecode) Status Reason (statuscode) Account (account) 0 Active 1 Active 1 Inactive 2 Inactive Activity (activitypointer) 0 Open 1 Open 1 Completed 2 Completed 2 Canceled 3 Canceled 3 Scheduled ...
go to top image