basic plugin Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/basic-plugin/ Microsoft Dynamics CRM . Microsoft Power Platform Wed, 25 Feb 2015 12:29:00 +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 basic plugin Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/basic-plugin/ 32 32 176351444 Activate / Deactivate a record using c# in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 ( using SetStateRequest ) http://microsoftdynamics.in/2015/02/25/activate-deactivate-a-record-using-c-in-ms-crm-2011-ms-crm-2013-ms-crm-2015-using-setstaterequest/ Wed, 25 Feb 2015 12:29:00 +0000 http://microsoftdynamics.in/2015/02/25/activate-deactivate-a-record-using-c-in-ms-crm-2011-ms-crm-2013-ms-crm-2015-using-setstaterequest/ hey , as we offensively get requirement to activate and reactivate a record then we start using update event , but there is a very simple method to do so , by using SetStateRequest : it require an assembly ” microsoft.crm.sdk.proxy.dll ” and using ” using Microsoft.Crm.Sdk.Messages;” . Code will be : SetStateRequest req = new SetStateRequest(); //the...

The post Activate / Deactivate a record using c# in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 ( using SetStateRequest ) appeared first on Microsoft Dynamics 365 Blog.

]]>

hey , as we offensively get requirement to activate and reactivate a record then we start using update event , but there is a very simple method to do so , by using SetStateRequest : it require an assembly ” microsoft.crm.sdk.proxy.dll ” and using ” using Microsoft.Crm.Sdk.Messages;” .
Code will be :
   SetStateRequest req = new SetStateRequest();
//the entity you want to change the state of
req.EntityMoniker = new EntityReference("new_abc", recordId);
//what should the new state be
req.State = new OptionSetValue(1);
//Pick an option from the status reason picklist to specify reason for state change
req.Status = new OptionSetValue(2);
SetStateResponse resp = (SetStateResponse)service.Execute(req);

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

The post Activate / Deactivate a record using c# in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 ( using SetStateRequest ) appeared first on Microsoft Dynamics 365 Blog.

]]>
2799
Create Activity Of An Phone Call On Create of Contact Using Plugin In MSCRM 2011 2013 http://microsoftdynamics.in/2014/03/24/create-activity-of-an-phone-call-on-create-of-contact-using-plugin-in-mscrm-2011-2013/ http://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.

]]>
http://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 http://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 http://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 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/ 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 http://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 http://microsoftdynamics.in/2014/03/19/update-value-in-another-entity-on-create-using-plugin-using-queryexpression-in-ms-crm-2011-2013/ http://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.

]]>
http://microsoftdynamics.in/2014/03/19/update-value-in-another-entity-on-create-using-plugin-using-queryexpression-in-ms-crm-2011-2013/feed/ 1 2830
Copy Field Value from One Entity To Another using Plugin in mscrm 2011 2013 http://microsoftdynamics.in/2014/03/19/copy-field-value-from-one-entity-to-another-using-plugin-in-mscrm-2011-2013/ Wed, 19 Mar 2014 10:41:00 +0000 http://microsoftdynamics.in/2014/03/19/copy-field-value-from-one-entity-to-another-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;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);                     new_teston test = (new_teston)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));                     //QueryExpression querry = new QueryExpression(new_testto.EntityLogicalName);            //querry.ColumnSet =...

The post Copy Field Value from One Entity To Another 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;
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);

       
            new_teston test = (new_teston)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));
        
            //QueryExpression querry = new QueryExpression(new_testto.EntityLogicalName);
            //querry.ColumnSet = new ColumnSet(true);
            //EntityCollection test1 = service.RetrieveMultiple(querry);
         
            //int count = test1.Entities.Count;

            //new_testto test11 = new new_testto();

            //for (int i = 0; i <= count; i++)
        
            new_testto tes = new new_testto();
            tes.new_name = “test”;
            tes.new_singlelineto = test.new_singleline;
         
            service.Create(tes);

        }
    }
}

SOURCE : JUST2CODE.COM

The post Copy Field Value from One Entity To Another using Plugin in mscrm 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2831
Plugin Tutorial 2 : Update and set “currency and date type” field Value On Create Of Record [ Basic Plugin ] in MS CRM 2011 2013 http://microsoftdynamics.in/2014/03/13/plugin-tutorial-2-update-and-set-currency-and-date-type-field-value-on-create-of-record-basic-plugin-in-ms-crm-2011-2013/ Thu, 13 Mar 2014 13:32:00 +0000 http://microsoftdynamics.in/2014/03/13/plugin-tutorial-2-update-and-set-currency-and-date-type-field-value-on-create-of-record-basic-plugin-in-ms-crm-2011-2013/ THIS PLUGIN SIMPLY UPDATE AN FIELD (currency) VALUE TO AN GIVEN VALUE ON CREATION OF NEW RECORD : AS CURRENCY TYPE HAS TO BE TYPE CAST TO “Money”.Currency Type Field  value can not be set as INT  or  STRING 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 plugin1 {     public class Class1 :IPlugin     {...

The post Plugin Tutorial 2 : Update and set “currency and date type” field Value On Create Of Record [ Basic Plugin ] in MS CRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
THIS PLUGIN SIMPLY UPDATE AN FIELD (currency) VALUE TO AN GIVEN VALUE ON CREATION OF NEW RECORD : AS CURRENCY TYPE HAS TO BE TYPE CAST TO “Money”.


Currency Type Field  value can not be set as INT  or  STRING




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

  // Retrieve all fields and records from the Entity “new_teston” 
            new_teston test = (new_teston)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet (true ));
                       // convert value into Money type            Money mon = new Money(1000000);
            test.new_currency = ( Money)mon;
// for date type  
                DateTime dnew = new DateTime (1991, 5, 22);

            test.new_dateonly = ( DateTime)dnew;

 service.Update(test);
         

        }
    }
}






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

The post Plugin Tutorial 2 : Update and set “currency and date type” field Value On Create Of Record [ Basic Plugin ] in MS CRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2832
Plugin Tutorial 1 : Update ” Single Line Of Text ” field Value On Create Of Record [ Basic Plugin ] in MS CRM 2011 2013 http://microsoftdynamics.in/2014/03/13/plugin-tutorial-1-update-single-line-of-text-field-value-on-create-of-record-basic-plugin-in-ms-crm-2011-2013/ Thu, 13 Mar 2014 12:29:00 +0000 http://microsoftdynamics.in/2014/03/13/plugin-tutorial-1-update-single-line-of-text-field-value-on-create-of-record-basic-plugin-in-ms-crm-2011-2013/ THIS PLUGIN SIMPLY UPDATE AN FIELD (SINGLE  LINE OF TEXT) VALUE TO AN GIVEN VALUE ON CREATION OF NEW RECORD : There are few things to do before writing your code follow the steps: 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 plugin1 {     public class Class1 : IPlugin     {         public void Execute( IServiceProvider serviceProvider)         {     ...

The post Plugin Tutorial 1 : Update ” Single Line Of Text ” field Value On Create Of Record [ Basic Plugin ] in MS CRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
THIS PLUGIN SIMPLY UPDATE AN FIELD (SINGLE  LINE OF TEXT) VALUE TO AN GIVEN VALUE ON CREATION OF NEW RECORD :

There are few things to do before writing your code follow the steps:



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 plugin1
{
    public class Class1 : IPlugin
    {
        public void Execute( IServiceProvider serviceProvider)
        {
           // Below three  line are to get service and context and will be same for all plugins
            IPluginExecutionContext context = (IPluginExecutionContext )serviceProvider.GetService(typeof (IPluginExecutionContext ));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory )serviceProvider.GetService( typeof( IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            // Retrieve all fields and records from the Entity “new_teston” 
            new_teston test = (new_teston )service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet (true ));
            // Store String “chetan” in Field new_singleline
            test.new_singleline = “chetan”;
            //service.update : to update the record , service.create : to create the record ,  service.delete : to delete
            service.Update(test);
         

        }
    }

}



NOTE  : Service.update : update the record (it don’t fire the plugin ) , Plugin Is Fired On Registering New Step In Plugin Registration Tool .





1. It Retrieve all field and there value from the entity ” new_teston 

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

2. Service.update : to update the record ,
    Service.create : to create the record ,
    Service.delete : to delete.

CLICK THE LINK TO SEE HOW TO BUILD .DLL FILE AND CONNECTION IN PLUGIN REGISTRATION TOOL

REGISTER NEW ASSEMBLY

BROWSE DLL FILE 


AFTER REGISTRATION 

NOW REGISTER NEW STEP (WHEN THE PLUGIN WILL FIRE)

WE WANT THE PLUGIN TO FIRE  ON CREATE OF NEW FORM

DONE


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

The post Plugin Tutorial 1 : Update ” Single Line Of Text ” field Value On Create Of Record [ Basic Plugin ] in MS CRM 2011 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2833