CRM 4 Recurring Workflow - 定时执行workflow

普通的workflow,设置简单,开发也不复杂,SDK里面带有例子。

最简单的CRM 4 workflow: 

[CrmWorkflowActivity("My Demo workflow")]
    public partial class MyDemo : Activity
	{
        public MyDemo()
        {

        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {

            try
            {
                //Debugger.Break();
                IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
                IWorkflowContext context = contextService.Context;

                // Create the CRM service
                ICrmService crmService = context.CreateCrmService();

                //get all contacts
                //            QueryExpression query = new QueryExpression();
                using (FileStream fileStream = new FileStream(@"C:\inetpub\wwwroot\cwf.log", FileMode.Append))
                {
                    byte[] data = System.Text.Encoding.UTF8.GetBytes(DateTime.Now.ToString());
                    fileStream.Write(data,0,data.Length);
                }
            }
            catch (Exception exc)
            {
                throw;
            }

            return ActivityExecutionStatus.Closed;
        }
	}

编译成dll

注册方式跟注册plugin一样,用现成的Plugin Registration tool 即可。

然后到Workflow page去设置,navigate to Settings->Workflow

新建一个Workflow, 并选择一个entity. 

其他设置:

图中第二步的Duration设置为1 minute,仅为测试,CRM 实际允许的是最少60分钟,否则CRM为认为你这个workflow是一个无限的workflow,并会自动停止。

over

参考:

http://gonzaloruizcrm.blogspot.com/2011/05/quite-often-we-have-business-process.html

如何打开CRM trace : http://support.microsoft.com/kb/907490/en-us

posted @ 2011-06-15 22:48  无尽思绪  阅读(1674)  评论(3编辑  收藏  举报