On






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