Sample Custom Workflow Activity To Create a Task

Create a Task

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("Create a Task")]
    public class CustomActivity : Activity
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

            IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
            IWorkflowContext context = contextService.Context;

            ICrmService crmService = context.CreateCrmService();

            DynamicEntity entity = new DynamicEntity();
            entity.Name = EntityName.task.ToString();
            entity.Properties = new PropertyCollection();
            entity.Properties.Add(new StringProperty("subject", taskId.Value.ToString()));
            entity.Properties.Add(new KeyProperty("activityid", new Key(taskId.Value)));

            return base.Execute(executionContext);

        public static DependencyProperty taskIdProperty =

        [CrmInput("The id")]
        [CrmOutput("The output")]
        public Lookup taskId
                return (Lookup)base.GetValue(taskIdProperty);
                base.SetValue(taskIdProperty, value);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s