Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

Custom Workflow to add two decimal fields.

(0) ShareShare
ReportReport
Posted on by 30

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

  • Verified answer
    Aman Shaw Profile Picture
    Aman Shaw 30 on at
    RE: Custom Workflow to add two decimal fields.

    Thank You very much for the response. This helped me a lot to understand the working.

  • Verified answer
    Satish1024 Profile Picture
    Satish1024 107 on at
    RE: Custom Workflow to add two decimal fields.

    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 ); } }

    }

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.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,431 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans