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

Popular posts from this blog

Power Automate - Update Child record when parent record is updated by using power automate in MS Dynamics CRM

set the active stage in Dynamics 365 when the option set value is "yes"