Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
namespace DecimalNumberTest
{
public class MyDecimalNumber : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
IOrganizationServiceFactory wod_serviceFactory = null;
IOrganizationService wod_CrmService = null;
try
{
wod_serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
wod_CrmService = wod_serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target")
&& context.InputParameters["Target"] is Entity)
{
Entity gitsPluginEntity = (Entity)context.InputParameters["Target"];
switch (context.MessageName)
{
case "Update":
if (gitsPluginEntity.LogicalName == "gits_violationrecord") //mod
{
decimal myNumber = gitsPluginEntity.GetAttributeValue<decimal>("gits_decimalnumber");
myNumber = myNumber + 1;
gitsPluginEntity["gits_decimalnumber"] = myNumber;
wod_CrmService.Update(gitsPluginEntity);
}
break;
}
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException(ex.Detail.InnerText);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}