创建一个dynamics CRM workflow - Development of Custom Workflows
Posted themiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建一个dynamics CRM workflow - Development of Custom Workflows相关的知识,希望对你有一定的参考价值。
首先我们需要确定windows workflow foundation 已经安装.
创建之后先移除MyCustomWorkflows 里面的 Activity.xaml
从packages\\Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.9.0.2.12\\tools 路径中添加以下两个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中
以上是关于创建一个dynamics CRM workflow - Development of Custom Workflows的主要内容,如果未能解决你的问题,请参考以下文章
如何在Dynamic CRM 2011中使用自定义Workflow
Dynamics CRM 2015-Custom Workflow Activity
Dynamics 365 CRM Connected Field Service 自动发送command
Dynamics CRM - 在 Dynamics CRM 开发中创建一个 Entity 对象