Simple Calculate Price Plugin Code For MS CRM
using System;
using Microsoft.Xrm.Sdk;
namespace YourNamespace
{
public class CalculatePricingPlugin : 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);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "your_entity_logical_name")
{
// Retrieve relevant attributes and perform pricing calculation
decimal quantity = ((decimal)entity.Attributes["quantity"]);
decimal unitPrice = ((Money)entity.Attributes["unitprice"]).Value;
// Perform custom pricing calculation logic
decimal totalPrice = quantity * unitPrice;
// Update the total price field
entity["totalprice"] = new Money(totalPrice);
}
}
}
}
}
Comments
Post a Comment