Hi Michel,
I am getting error I am using following code.
I registered it in preoperation event
Message - update
Filter attribute - success
So when ever success option set change i want to do some calculation by taking its previous value.
Means it if it 10% and user change 10% to 20% then i want to fetch 10% and then i will do some calculation
and then i will update a another field.
Kindly suggest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
namespace PreopAgingChanceofSuccess
{
public classSuccess :IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
tracingService.Trace("Plugin enetering in update");
try
{
int statusCode = 0;
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
if (context.Depth > 1) { return; }
//obtain the target entity from input parameters
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.Attributes.Contains("kkk_chanceofsuccess")) // getting error in this line
{
string optionsetScuccess = entity.FormattedValues["kkk_chanceofsuccess"].ToString();
optionsetChanceofScuccess = Regex.Replace(optionsetChanceofScuccess, "[^0-9]+", string.Empty);
throw new InvalidPluginExecutionException(optionsetScuccess);
}
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException(ex.Message.ToString());
}
catch (Exception ex)
{
tracingService.Trace(ex.ToString());
throw;
}
}
}
}
error -
Unexpected exception from plug-in (Execute): PreopSuccess.PreOperationSuccess: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. If you contact support, please provide the technical details.