On
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_attendee obj = (new_attendee)service.Retrieve(new_attendee.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));
if (obj.new_AttendeeName != null)
{
Guid emp = obj.new_AttendeeName.Id;
new_employee employee = (new_employee)service.Retrieve(new_employee.EntityLogicalName, emp, new ColumnSet(true));
Guid desig = employee.new_Designation.Id;
Guid dep = employee.new_Department.Id;
Guid manag = employee.new_ManagerId.Id;
EntityReference reff1 = new EntityReference(new_department.EntityLogicalName, dep);
EntityReference reff = new EntityReference(new_designation.EntityLogicalName, desig);
EntityReference reff2 = new EntityReference(new_employee.EntityLogicalName, manag);
obj.new_Designation = reff;
obj.new_Department = reff1;
obj.new_Manager = reff2;
obj.new_AttendeeCode = employee.new_EmployeeCode;
service.Update(obj);
}
}
}
}


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