update entity Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/update-entity/ Microsoft Dynamics CRM . Microsoft Power Platform Wed, 19 Mar 2014 10:47: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 update entity Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/update-entity/ 32 32 176351444 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