Please wait, loading...

 

Copy Field Value from One Entity To Another using Plugin in mscrm 2011 2013

March 19, 2014

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

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651&ssl=1
Microsoft Dynamics Community Profile

Learn more