PLUGIN Archives - Microsoft Dynamics 365 Blog https://microsoftdynamics.in/category/plugin/ Microsoft Dynamics CRM . Microsoft Power Platform Sat, 25 Apr 2020 08:42:04 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/cropped-Microsoftdynamics365-blogs.png?fit=32%2C32&ssl=1 PLUGIN Archives - Microsoft Dynamics 365 Blog https://microsoftdynamics.in/category/plugin/ 32 32 176351444 Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins/Workflows https://microsoftdynamics.in/2018/08/16/passing-data-from-dynamics-365-to-azure-service-bus-queue-using-plugins-workflows/ Thu, 16 Aug 2018 12:18:01 +0000 https://www.inogic.com/blog/?p=12658 Introduction: Recently we had a business requirement where we need to pass data from Dynamics 365 CRM to Azure Service Bus queue through plugins and workflows. After some research and play around we found a solution for this. For this, we require an Azure Service Bus, an Azure function and a webhook. The CRM data...

The post Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins/Workflows appeared first on Microsoft Dynamics 365 Blog.

]]>
Introduction:

Recently we had a business requirement where we need to pass data from Dynamics 365 CRM to Azure Service Bus queue through plugins and workflows. After some research and play around we found a solution for this.

For this, we require an Azure Service Bus, an Azure function and a webhook. The CRM data can be delivered to azure portal using the webhook. The webhook is registered to connect to the azure function. When plugin/workflow is triggered, webhook is called from the code which passes the data to azure function in JSON format and azure function is used to add the data to the queue of Azure service bus (ASB).

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

The detailed steps are as follows:-

1. Create an Azure Service Bus:-

Open Azure portal in your CRM organization and Create Service Bus Namespace by navigating to + Create a Resource >> Integration >> Service Bus

2. Create an Azure function which will add the CRM data to Azure Service Bus Queue:-

a. Navigate to + Create a Resource >> Compute >> Function App

b. Create a C# HttpTrigger Function in it

c. Click on “Get function URL” link

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

This URL link is important and will be used in CRM Plugin/Workflow code and webhook registration.

d. Click on Integrate and + New Output to create a queue in ASB and provide it to Azure function

assing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

e. Select Azure Service Bus

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

f. Select “Service Bus Queue” in Message Type. You can select the “Service Bus Connection” by clicking on new and selecting the desired Service Bus.

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

g. Click on the function “f functionname” and paste the following code to add the JSON data from CRM to the ASB Queue in the azure function. Save the code.

using System;
using System.Net;
public static async Task<object> Run(HttpRequestMessage req,IAsyncCollector<Object> outputSbMsg, TraceWriter log)
{ log.Info($"Webhook was triggered!"); string jsonContent = await req.Content.ReadAsStringAsync(); log.Info("jsonContent " + jsonContent); await outputSbMsg.AddAsync(jsonContent); log.Info("added to queue"); return req.CreateResponse(HttpStatusCode.OK);
}

Here,     HttpRequestMessage req is  JSON data from CRM

IAsyncCollector<Object> outputSbMsg  is  ASB Queue name

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

3. Assume we are sending the data of Account entity to Azure Service Bus (ASB). The data should be in JSON format before it is passed to Azure portal. Below is the plugin/workflow code:-

// Create a Class having members as data attributes to be passed to Azure
[DataContract]
public class AccountObj
{
[DataMember]
public string AccountID { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Telephone { get; set; }
}
// Insert the following code after getting the primary entity in Plugin/workflow
using System.IO;
using System.Net;
using System.Runtime.Serialization.Json;//Install from NuGet Package Manager using (WebClient client = new WebClient())
{
// Prepare Json data DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AccountObj));
MemoryStream memoryStream = new MemoryStream();
serializer.WriteObject(memoryStream, accObj);
var jsonObject = Encoding.Default.GetString(memoryStream.ToArray()); // Prepare WebHook
var webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json"; // Azure Function key
var code = "xPhPPB5tGCq86NRbe7wzgJika3bv4ahP9kw7xe5Asoja2vEk4fPqVw==&clientId=default";
// Azure Function Url
var serviceUrl = "https://callwebhookfromcrmassebly.azurewebsites.net/api/GenericWebhookCSharp1?code=" + code; // upload the json data to the serviceurl string response = webClient.UploadString(serviceUrl, jsonObject); }

4. Webhook Registration:-

With July 2017 Update, now we have the option to register a new Webhook through Plugin Registration tool. Download the latest Plugin Registration Tool from NuGet using the PowerShell script 

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/download-tools-nuget.

Through registering a Webhook, we can send data (execution context) about any operation performed on Dynamics 365 to the external services or application. The execution context information is passed in JSON format here.

a. Open Plugin Registration tool and Register New WebHook

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

b. Enter details of registration from the “Get function URL” from step 2c

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

5. Register your plugin/workflow assembly.

Working: – In the example, when “Account Number” of an account record is changed, the plugin/workflow is triggered which executes the webhook. The webhook passes the data to azure function and the azure function adds the data to queue. The result can be seen as below in the azure function Monitor section.

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins Workflows

The CRM data is added as a message in the Queue of Azure service Bus as seen in the above screenshot.

Conclusion:

Using the simple steps above user can pass data from Dynamics 365 to Azure Service Bus Queue using Plugins/Workflows.

Integrate Dynamics CRM Online QuickBooks

Source

The post Passing data from Dynamics 365 to Azure Service Bus Queue using Plugins/Workflows appeared first on Microsoft Dynamics 365 Blog.

]]>
4360
Create Your First Plugin Dynamics Microsoft Dynamics CRM – Part 1 https://microsoftdynamics.in/2017/12/20/create-your-first-plugin-dynamics-ms-crm/ Wed, 20 Dec 2017 09:39:00 +0000 http://microsoftdynamics.in/2017/12/20/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...

The post Create Your First Plugin Dynamics Microsoft Dynamics CRM – Part 1 appeared first on Microsoft Dynamics 365 Blog.

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

 

The post Create Your First Plugin Dynamics Microsoft Dynamics CRM – Part 1 appeared first on Microsoft Dynamics 365 Blog.

]]>
2764
How to Change Business process Flow ( bpf ) of an entity using plugin C# in MS CRM 2011 , 2013 , 2015 https://microsoftdynamics.in/2015/09/07/how-to-change-business-process-flow-bpf-of-an-entity-using-plugin-c-in-ms-crm-2011-2013-2015/ Sun, 06 Sep 2015 18:49:00 +0000 http://microsoftdynamics.in/2015/09/07/how-to-change-business-process-flow-bpf-of-an-entity-using-plugin-c-in-ms-crm-2011-2013-2015/ Plugin can be written to dynamicaly change BPF ( bussiness process flow ) of an entity acc to diffrent condition or Configrations ,  It requires Two main Id 1. ProcessID : to get workflowID2. StageID Of that process. Below is the code to change bpf of an entity using plugin :  QueryExpression queryworkflow = new...

The post How to Change Business process Flow ( bpf ) of an entity using plugin C# in MS CRM 2011 , 2013 , 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
Plugin can be written to dynamicaly change BPF ( bussiness process flow ) of an entity acc to diffrent condition or Configrations ,  It requires Two main Id

1. ProcessID : to get workflowID
2. StageID Of that process.

Below is the code to change bpf of an entity using plugin :

 QueryExpression queryworkflow = new QueryExpression(Workflow.EntityLogicalName);
            queryworkflow.ColumnSet = new ColumnSet(true);
          ConditionExpression cond1 =  new ConditionExpression(“workflowid”, ConditionOperator.Equal, processId);
         ConditionExpression cond2 =   new ConditionExpression(“statecode”, ConditionOperator.Equal, 1);
         FilterExpression filter = new FilterExpression();
         filter.Conditions.Add(condition1);
         filter.Conditions.Add(condition2);

         queryworkflow .Criteria.AddFilter(filter);
         EntityCollection workflowcoll = service.RetrieveMultiple(queryworkflow);

// get default stage id of that process

            QueryExpression querystage = new QueryExpression(“processstage”);
            querystage.ColumnSet = new ColumnSet(true);
            ConditionExpression cond1 = new ConditionExpression(“stagecategory”, ConditionOperator.Equal, 0);
            ConditionExpression cond2 = new ConditionExpression(“processid”, ConditionOperator.Equal, workflowcoll.Entities[0].Id);
            FilterExpression filter1 = new FilterExpression();
            filter1.Conditions.Add(condition1);
            filter1.Conditions.Add(condition2);

            querystage.Criteria.AddFilter(filter1);
            EntityCollection stagecoll = service.RetrieveMultiple(querystage);

            // update the fields in entity to change the BPF 

             Entity providedentity = new Entity(entity.LogicalName);
            providedentity.Id = entity.Id;
                providedentity[“processid”] = workflowcoll.Entities[0].Id;
                providedentity[“stageid”] = stagecoll.Entities[0].Id;
                service.Update(providedentity);

Thats all Entity BPF Will be auto assigned as given in Code .

Hope this Helpled you , for any query or suggestion please coment below , thanks


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

The post How to Change Business process Flow ( bpf ) of an entity using plugin C# in MS CRM 2011 , 2013 , 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
2790
Get / Retrieve all Entity Metadata from an organization in MSCRM 2011, 2013 ,2015 usin C# https://microsoftdynamics.in/2015/09/01/get-retrieve-all-entity-metadata-from-an-organization-in-mscrm-2011-2013-2015-usin-c/ Tue, 01 Sep 2015 11:45:00 +0000 http://microsoftdynamics.in/2015/09/01/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) ...

The post Get / Retrieve all Entity Metadata from an organization in MSCRM 2011, 2013 ,2015 usin C# appeared first on Microsoft Dynamics 365 Blog.

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

The post Get / Retrieve all Entity Metadata from an organization in MSCRM 2011, 2013 ,2015 usin C# appeared first on Microsoft Dynamics 365 Blog.

]]>
2795
Create Activity Of An Phone Call On Create of Contact Using Plugin In MSCRM 2011 2013 https://microsoftdynamics.in/2014/03/24/create-activity-of-an-phone-call-on-create-of-contact-using-plugin-in-mscrm-2011-2013/ https://microsoftdynamics.in/2014/03/24/create-activity-of-an-phone-call-on-create-of-contact-using-plugin-in-mscrm-2011-2013/#comments Mon, 24 Mar 2014 13:17:00 +0000 http://microsoftdynamics.in/2014/03/24/create-activity-of-an-phone-call-on-create-of-contact-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 ClassLibrary1{    public class Class1 : IPlugin    {        public void Execute(IServiceProvider serviceProvider)        {            IPluginExecutionContext context = (IPluginExecutionContext)             serviceProvider.GetService(typeof(IPluginExecutionContext));            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));   ...

The post Create Activity Of An Phone Call On Create of Contact Using Plugin In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>

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 ClassLibrary1
{
    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);

            Contact test = (Contact)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));

            PhoneCall phone = new PhoneCall();

            ActivityParty _from = new ActivityParty();
            _from.PartyId = new EntityReference(SystemUser.EntityLogicalName, context.UserId);

            ActivityParty _to = new ActivityParty();
            _to.PartyId = new EntityReference(Contact.EntityLogicalName, test.Id);

            phone.From = new ActivityParty[] { _from };
            phone.PhoneNumber = “9028170672”;
            phone.DirectionCode = true;   // true is for outgoing and false is for incoming
            phone.Subject = “phone call trial”;
            phone.To = new ActivityParty[] { _to };
            service.Create(phone);
        }

    }
}


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

The post Create Activity Of An Phone Call On Create of Contact Using Plugin In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
https://microsoftdynamics.in/2014/03/24/create-activity-of-an-phone-call-on-create-of-contact-using-plugin-in-mscrm-2011-2013/feed/ 1 2825
Create Email Activity OR Send Email using Plugin In MSCRM 2011 2013 https://microsoftdynamics.in/2014/03/24/create-email-activity-or-send-email-using-plugin-in-mscrm-2011-2013/ Mon, 24 Mar 2014 10:46:00 +0000 http://microsoftdynamics.in/2014/03/24/create-email-activity-or-send-email-using-plugin-in-mscrm-2011-2013/  Note: On create on new Contact An Email activity generates and email is assigned.  using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Runtime.Serialization;using System.ServiceModel;using Microsoft.Xrm.Client;using Microsoft.Xrm.Portal;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Query;using Microsoft.Crm.Sdk.Messages;namespace ClassLibrary1{    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);            //  _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());           Contact...

The post Create Email Activity OR Send Email using Plugin In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>

 Note: On create on new Contact An Email activity generates and email is assigned.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Portal;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;
namespace ClassLibrary1
{
    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);

           //  _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
           Contact con = (Contact)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));
           Guid _contactId = con.Id;

          // Create the ‘From:’ activity party for the email
             ActivityParty fromParty = new ActivityParty
             {
                 PartyId = new EntityReference(SystemUser.EntityLogicalName, context.UserId)
             };

            // Create the ‘To:’ activity party for the email
             ActivityParty toParty = new ActivityParty
            {
                PartyId = new EntityReference(Contact.EntityLogicalName, _contactId)
            };

            // Create an e-mail message.
            Email email = new Email
            {
                To = new ActivityParty[] { toParty },
                From = new ActivityParty[] { fromParty },
                Subject = “e-mail”,
                Description = “SendEmail Message.”,
                DirectionCode = true
            };
            Guid _emailId = service.Create(email);

            // Use the SendEmail message to send an e-mail message.
            SendEmailRequest sendEmailreq = new SendEmailRequest
            {
                EmailId = _emailId,
                TrackingToken = “”,
                IssueSend = true
            };

            SendEmailResponse sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);
        }
    }
}


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

The post Create Email Activity OR Send Email using Plugin In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2826
Get Optionset Value and Lable Using Plugin (OptionSet Label / text ) In MSCRM 2011 , 2013 https://microsoftdynamics.in/2014/03/20/get-optionset-value-and-lable-using-plugin-optionset-label-text-in-mscrm-2011-2013/ Thu, 20 Mar 2014 13:16:00 +0000 http://microsoftdynamics.in/2014/03/20/get-optionset-value-and-lable-using-plugin-optionset-label-text-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 System.ServiceModel;using Microsoft.Xrm.Client;using Microsoft.Xrm.Portal;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Query;using Microsoft.Xrm.Sdk.Messages;using Microsoft.Xrm.Sdk.Metadata; namespace ClassLibrary2{    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);             // Retrive All Vlaue From Single Record on which pluging is...

The post Get Optionset Value and Lable Using Plugin (OptionSet Label / text ) In MSCRM 2011 , 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>

 using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Portal;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

namespace ClassLibrary2
{
    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);

            // Retrive All Vlaue From Single Record on which pluging is fired
             new_teston test = (new_teston)service.Retrieve(new_teston.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));

            // “s” Contain OptionSet Value ( s = 1 , 2 , 3 , …)
             int s = Convert.ToInt32(((OptionSetValue)test.Attributes[“new_optionset”]).Value);

            // Function For Retriving OptionSet Label Through Value of “s”
             string ss = GetPickListText(new_teston.EntityLogicalName, “new_optionset”, s, service);

             new_testto tes = new new_testto();
             tes.new_name = ss;

            service.Create(tes);
        }

        public string GetPickListText(string entityName, string attributeName, int optionSetValue, IOrganizationService service)
         {
             string AttributeName = attributeName;
             string EntityLogicalName = entityName;

            RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest();
            retrieveDetails.EntityFilters = EntityFilters.All;
            retrieveDetails.LogicalName = EntityLogicalName;

            RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
             EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;

            PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;

            OptionSetMetadata options = picklistMetadata.OptionSet;
             IList<OptionMetadata> picklistOption = (from o in options.Options where o.Value.Value == optionSetValue select o).ToList();
             string picklistLabel = (picklistOption.First()).Label.UserLocalizedLabel.Label;

             return picklistLabel;

        }

     }

}


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

The post Get Optionset Value and Lable Using Plugin (OptionSet Label / text ) In MSCRM 2011 , 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2827
Copy One LookUp Field Value To Anoher LookUp using Plugin (EntityReference) ( Copy Lookup to Lookup ) In MSCRM 2011 2013 https://microsoftdynamics.in/2014/03/20/copy-one-lookup-field-value-to-anoher-lookup-using-plugin-entityreference-copy-lookup-to-lookup-in-mscrm-2011-2013/ Thu, 20 Mar 2014 11:18:00 +0000 http://microsoftdynamics.in/2014/03/20/copy-one-lookup-field-value-to-anoher-lookup-using-plugin-entityreference-copy-lookup-to-lookup-in-mscrm-2011-2013/ Note : There is two way to copy lookup to Lookup value . 1. Both Lookup are on same entity  //   tes.new_testonlookups= test.new_testonlookup; 2 using EntityRefrence if the Process include more than 2 Entities. using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Runtime.Serialization;using System.ServiceModel;using Microsoft.Xrm.Client;using Microsoft.Xrm.Portal;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Query; namespace ClassLibrary2{    public class Class1 : IPlugin    {        public...

The post Copy One LookUp Field Value To Anoher LookUp using Plugin (EntityReference) ( Copy Lookup to Lookup ) In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
Note : There is two way to copy lookup to Lookup value .

1. Both Lookup are on same entity  //   tes.new_testonlookups= test.new_testonlookup;

2 using EntityRefrence if the Process include more than 2 Entities.

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

namespace ClassLibrary2
{
    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);

            // retrive record data/value on which plugin firing
            new_calculate test = (new_calculate)service.Retrieve(new_calculate.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));

            // r contain Guid of the look up
            Guid r = test.new_testonlookup.Id;

     

            // retrive fields from 2nd entity where wants to copy the string
            new_testto tes = new new_testto();
            tes.new_name = test.new_name;
         
            // reff1 Cantain Reffrence of lookup with guid r
            EntityReference reff1 = new EntityReference(new_teston.EntityLogicalName, r);
            tes.new_testonlookups = reff1;

            // tes.new_testonlookups= test.new_testonlookup;  ( we can copy one look up to another lookup of same entity directlly )
             service.Create(tes);

        }

    }

}


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

The post Copy One LookUp Field Value To Anoher LookUp using Plugin (EntityReference) ( Copy Lookup to Lookup ) In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2828
Copy Look up Value to Single Line Of Text (String) Using Plugin In MSCRM 2011 2013 https://microsoftdynamics.in/2014/03/20/copy-look-up-value-to-single-line-of-text-string-using-plugin-in-mscrm-2011-2013/ Thu, 20 Mar 2014 09:37:00 +0000 http://microsoftdynamics.in/2014/03/20/copy-look-up-value-to-single-line-of-text-string-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 System.ServiceModel;using Microsoft.Xrm.Client;using Microsoft.Xrm.Portal;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Query; namespace ClassLibrary2{    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);             // retrive record data/value on which plugin firing            new_calculate test = (new_calculate)service.Retrieve(new_calculate.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));             //...

The post Copy Look up Value to Single Line Of Text (String) Using Plugin In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>

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

namespace ClassLibrary2
{
    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);

            // retrive record data/value on which plugin firing
            new_calculate test = (new_calculate)service.Retrieve(new_calculate.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));

            // r contain Guid of the look up
            Guid r = test.new_testonlookup.Id;

            // retriving record data/value of single record of which lookup is ( as “r” contain its guid)
            new_teston stringcopy = (new_teston)service.Retrieve(new_teston.EntityLogicalName, r, new ColumnSet(true));

            // retrive fields from 2nd entity where wants to copy the string
            new_testto tes = new new_testto();
            tes.new_name = stringcopy.new_teston1;

            // coping string to an fiel on same entity
            test.new_stringcopied = stringcopy.new_teston1;

            service.Create(tes);
            service.Update(test);
        }

    }

}

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

The post Copy Look up Value to Single Line Of Text (String) Using Plugin In MSCRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2829
Update value in another entity on create using plugin ( Using QueryExpression ) in ms crm 2011 2013 https://microsoftdynamics.in/2014/03/19/update-value-in-another-entity-on-create-using-plugin-using-queryexpression-in-ms-crm-2011-2013/ https://microsoftdynamics.in/2014/03/19/update-value-in-another-entity-on-create-using-plugin-using-queryexpression-in-ms-crm-2011-2013/#comments Wed, 19 Mar 2014 10:47:00 +0000 http://microsoftdynamics.in/2014/03/19/update-value-in-another-entity-on-create-using-plugin-using-queryexpression-in-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 System.ServiceModel;using Microsoft.Xrm.Client;using Microsoft.Xrm.Portal;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Query;using Microsoft.Xrm.Sdk.Messages; namespace plugin1 {    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);            // Only Retrieve The Data From The Record On Which Plugin Is Firing            new_teston...

The post Update value in another entity on create using plugin ( Using QueryExpression ) in ms crm 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Portal;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages
;

namespace plugin1

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

           // Only Retrieve The Data From The Record On Which Plugin Is Firing
            new_teston test = (new_teston)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));

            //Select * From new_testto
            QueryExpression querry = new QueryExpression(new_testto.EntityLogicalName);

            //It Will Retrieve All Fields , If Wants Specific Field : Instead Of True Write Field Name
            querry.ColumnSet = new ColumnSet(true);

            // test1 Has All Records In Entity new_testto
            EntityCollection test1 = service.RetrieveMultiple(querry);

     

            // The Loop Will Run For No Of Record Available

            for (int i = 0; i <= count; i++){     
                // test11 Has All Field Value From i(1-2-3—) Records
                new_testto test11 = (new_testto)test1.Entities[i];

                if (test.new_teston1 == test11.new_name) {
                    test11.new_singlelineto = test.new_singleline;

                }
              service.Update(test11);

            }

        }

    }

}


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

The post Update value in another entity on create using plugin ( Using QueryExpression ) in ms crm 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
https://microsoftdynamics.in/2014/03/19/update-value-in-another-entity-on-create-using-plugin-using-queryexpression-in-ms-crm-2011-2013/feed/ 1 2830