Hello
I have the code below which works fine in pre-operation and pre-image. But I need it to work in post-operation. Any ideas on how to adjust the code?
using System;
using Microsoft.Xrm.Sdk;
namespace CalculateScorePlugin
{
public class CalculateScore : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService client = servicefactory.CreateOrganizationService(context.UserId);
{
if (context.InputParameters.Contains("Target"))
{
if (context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "contact")
{
if (entity.Attributes.Contains("crmn_ourdescription"))
{
try
{
Entity image = context.PreEntityImages["image"];
/*
int sumFakturert = image.GetAttributeValue<int>("crmn_invoiceamount");
int antTimerOrdinarTid = image.GetAttributeValue<int>("crmn_workinghoursordinary");
int antOppdrag = image.GetAttributeValue<int>("crmn_assignmentinvolvements");
*/
int kundelikes = image.GetAttributeValue<int>("new_kundelikes");
String forsteVurdering = image.FormattedValues["new_frstegangsvurdering"].ToString();
int score = kundelikes * 100;
entity.Attributes["description"] = score.ToString();
//entity.Attributes.Add("description", test);
//client.Update(entity);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("Howdy! An error occured in the plugin:", ex);
}
}
}
else return;
}
}
}
}
}
}
*This post is locked for comments
I have the same question (0)