I want to write a custom workflow to add two decimal fields in Account Entity and store the result in a different field. Can anyone suggest the simplest way to achieve this via custom workflows? I don't want to use calculated fields or JS.
Thank You
There you go. I have written code for you. Make sure you create a built-in workflow and call this one from it.
For tutorials on Custom Workflows, you can visit my course https://www.udemy.com/dynamics-365-crm-developer-technical-training/
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Workflow; using System.Activities; namespace MyCustomWorkflows { public class GetTaxWorkflow : CodeActivity { [Input("Value1")] public InArgument<Decimal> Value1 { get; set; } [Input("Value2")] public InArgument<Decimal> Value2 { get; set; } [Output("Sum")] public OutArgument<Decimal> Sum { get; set; } protected override void Execute(CodeActivityContext executionContext) { //Create the tracing service ITracingService tracingService = executionContext.GetExtension<ITracingService>(); //Create the context IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); decimal value1 = Value1.Get(executionContext); decimal value2 = Value2.Get(executionContext); Sum.Set(executionContext, value1 + value2 ); } } }
Thank You very much for the response. This helped me a lot to understand the working.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to a top community star!
In our never-ending quest to help the Dynamics 365 Community members get answers faster …
Welcome to the next edition of the Community Platform Update. This is a status …
Stay up to date on forum activity by subscribing.