Please wait, loading...

 

GET AND SET VALUES FROM ONE ENTITY TO ANOTHER ENTITY USING PLUGIN IN MSCRM 2011 , 2013

February 14, 2014
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 elite_employee
{
    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_bankreconciliation reconcil = (new_bankreconciliation)service.Retrieve(new_bankreconciliation.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));
            if (reconcil.new_BankAccount != null)
            {
                Guid bank = reconcil.new_BankAccount.Id;

                New_bank bk = (New_bank)service.Retrieve(New_bank.EntityLogicalName, bank, new ColumnSet(true));
                reconcil.new_BalanceLastStatement = bk.New_Balance;
                reconcil.new_StatementEndingBalance = bk.new_BalanceLastStatement;
                service.Update(reconcil);
            }
        }
    }
}

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

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

Learn more