PreImage and PostImage
Plugin Code for Pre Image and Post Image:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling;
namespace CheckImageQuery
{
public class checkImage : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
try
{
if (context.Depth == 1)
{
Entity entity = (Entity)context.InputParameters["Target"];
Entity preImage = (Entity)context.PreEntityImages["preImagee"];
Entity postImage = (Entity)context.PostEntityImages["PostImage"];
string preContactImage = preImage.GetAttributeValue<string>("telephone1");
string postContactImage = postImage.GetAttributeValue<string>("telephone1");
tracing.Trace("Pre-image phone number: {0} ", preContactImage);
tracing.Trace("Post-image number: {0}", postContactImage);
}
}
catch(InvalidPluginExecutionException ex)
{
throw new InvalidPluginExecutionException(ex.Message.ToString());
}
}
*(or)*
//
//if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
//{
// try
// {
// if (context.Depth == 1)
// {
// Entity entity = (Entity)context.InputParameters["Target"];
// Entity preImage = (Entity)context.PreEntityImages["preImagee"];
// Entity postImage = (Entity)context.PostEntityImages["PostImage"];
// Entity updateContact = new Entity("contact");
// updateContact.Id = entity.Id;
// updateContact["mobilephone"] = preImage.Attributes["telephone1"];
// updateContact["fax"] = postImage.Attributes["telephone1"];
// service.Update(updateContact);
// }
// }
// catch (InvalidPluginExecutionException ex)
// {
// throw new InvalidPluginExecutionException(ex.Message.ToString());
// }
//}
}
}
}
Follow the YouTube Link To Get Clarity : https://youtu.be/BNpqbt8NDhw?si=JMLV1fOHE1ZUpzoQ
Comments
Post a Comment