創建一個dynamics CRM workflow (四) - Development of Custom Workflows
阿新 • • 發佈:2019-05-11
over 鍵值 def retrieve aci tools 安裝 rri eve
首先我們需要確定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