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中

  • 相关阅读:
    jQuery.noConflict() 函数详解
    Meta标签用法大全
    解决
    如何在同一台服务器上安装多套通达OA
    Android UI设计系统-android selector 开始自定义样式
    Android UI设计系统---LayoutParams[转]
    jquery Ajax应用总结
    阿里云主机安装Memcached
    PHP搭建OAuth2.0
    制作干净系统 批处理删除所有设备驱动
  • 原文地址:https://www.cnblogs.com/TheMiao/p/10834561.html
Copyright © 2011-2022 走看看