Export (0) Print
Expand All

Custom Workflow Activity: Return a Calculated Value

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

The following sample workflow activity demonstrates how to return a calculated value from an activity.

This sample code can be found in the following files in the SDK download:

Server\FullSample\CustomWorkflowActivity\CS\AddActivity.cs
Server\FullSample\CustomWorkflowActivity\VB\AddActivity.cs

Example

using System;
using System.Collections;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Reflection;

using Microsoft.Crm.Workflow;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Sdk.Query;

namespace SampleWorkflows
{
    [CrmWorkflowActivity("Return a Calculated Value")]
    public class AddActivity : Activity
    {

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            result = new CrmNumber(a.Value + b.Value);
            return base.Execute(executionContext);
        }

        public static DependencyProperty aProperty =
           DependencyProperty.Register("a",
           typeof(CrmNumber),
           typeof(AddActivity));

        [CrmInput("a")]
        public CrmNumber a
        {
            get
            {
                return (CrmNumber)base.GetValue(aProperty);
            }
            set
            {
                base.SetValue(aProperty, value);
            }

        }

        public static DependencyProperty bProperty =
           DependencyProperty.Register("b",
           typeof(CrmNumber),
           typeof(AddActivity));

        [CrmInput("b")]
        public CrmNumber b
        {
            get
            {
                return (CrmNumber)base.GetValue(bProperty);
            }
            set
            {
                base.SetValue(bProperty, value);
            }

        }

        public static DependencyProperty resultProperty =
           DependencyProperty.Register("result",
           typeof(CrmNumber),
           typeof(AddActivity));

        [CrmOutput("result")]
        public CrmNumber result
        {
            get
            {
                return (CrmNumber)base.GetValue(resultProperty);
            }
            set
            {
                base.SetValue(resultProperty, value);
            }

        }
    }
}

See Also

Concepts


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft