zoukankan      html  css  js  c++  java
  • 创建一个dynamics CRM workflow (四)

     首先我们需要确定windows workflow foundation 已经安装.

    创建之后先移除MyCustomWorkflows 里面的 Activity.xaml

    从packagesMicrosoft.CrmSdk.XrmTooling.PluginRegistrationTool.9.0.2.12 ools 路径中添加以下两个reference

    复制下面的代码到我们新建的GetTaxWorkflow.cs

    因为我们在CRM里面定义的custom entity是键值对的形式出现, 所以我们需要input值和output值.

    我们有以下几个方式获取数据. 这里我们使用Query By Attribute

    1. UsingRetrieve (必须获得GUID)

    2. QueryExpression (可以实现复杂的逻辑)

    3. Query By Attribute (简化的QueryExpression)

    4. FatchXML

    5. LINQ

        public class GetTaxWorkflow : CodeActivity
        {
            [Input("Key")]
            public InArgument<string> Key { get; set; }
    
            [Output("Tax")]
            public OutArgument<string> Tax { 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);
    
                var key = Key.Get(executionContext);
    
                // Get data from Configuraton Entity
                // Call organization web service
    
                QueryByAttribute query = new QueryByAttribute("contoso_configuration");
                query.ColumnSet = new ColumnSet(new string[] { "contoso_value" });
                query.AddAttributeValue("contoso_name", key);
                EntityCollection collection = service.RetrieveMultiple(query);
    
                if (collection.Entities.Count != 1)
                {
                    tracingService.Trace("Something is wrong with configuration");
    
                }
    
                Entity config = collection.Entities.FirstOrDefault();
    
                tracingService.Trace(config.Attributes["contoso_value"].ToString());
                Tax.Set(executionContext, config.Attributes["contoso_value"].ToString());
            }
        }

    记得注册这个assembly

    然后让我们build一下项目. 我们的workflow dll就会在debug中

  • 相关阅读:
    [学习笔记]分组数据以及on/where/having的顺序问题
    java开发流程(未完成)
    首发测试
    免费的网上问卷调查程序
    德广火车票助手登录12306代码详解登录
    vs2008 SmartDevice 程序 访问Internet时出错 提示:未能建立与网络的连接。解决方案
    使用U盘安装Windows Server2008
    德广火车票助手源码 请各位前辈给些建议
    关于微软有自增列父子表更新程序的问题
    在线HTML标签验证工具.很好用的.
  • 原文地址:https://www.cnblogs.com/TheMiao/p/10834561.html
Copyright © 2011-2022 走看看