首先我们需要确定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 != )
{
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的更多相关文章

  1. 创建一个dynamics CRM workflow (一) - Introduction to Custom Workflows

    Workflow: Use this process to model and automate real world business processes. These processes can ...

  2. 创建一个dynamics CRM workflow (三) - Creating Configuration Entity for Custom Workflow

    上个帖子中, 我们创建了个发email的workflow. 但是我们邮件当中的tax 值是 hard code, 这在开发当中是不容许的. 那今天我们来把这个build in workflow用 in ...

  3. 创建一个dynamics CRM workflow (二) - Build in Workflows

    这里我们不着重讲解build in workflow. 但是, 如果要上手custom workflow, 我们必须要了解 build in workflow. build-in workflow 在 ...

  4. 创建一个dynamics CRM workflow (五) - Deploy Custom Workflows

    我们打开plugin registeration tool. 注册一个新的assembly. custom workflow 和 plugin注册的方法还有些不同. 这一步custom workflo ...

  5. 创建一个dynamics CRM workflow (六) - Debugging Custom Workflows

    我们也deploy部署了custom workflows, debugging是开发当中不可或缺的一个步骤. debug workflow的步骤和debug有些许不一样: 1. install pro ...

  6. 创建一个dynamics 365 CRM online plugin (四) - PreValidation

    开始之前,我们要确认一下 Plugin 的 pipeline. PreValidation -> PreOperation -> Server Side System Main Event ...

  7. 创建一个dynamics 365 CRM online plugin (九) - Context.Depth

    让我们来看看官方文档是怎么讲的 https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide ...

  8. 创建一个dynamics 365 CRM online plugin (七) - plugin当中的Impersonation角色

    我们之前创建的plugin都是使用default的 run in User's Context. 理解就是使用正在登陆的security context用户信息 那有个问题,如果当前用户的securi ...

  9. 创建一个dynamics 365 CRM online plugin (十) - Isolation mode or trust mode

    Isolation Mode 也被称作为Plugin Trust CRM里面有两种plugin trust / isolation mode 1. Full Trust 只在OP系统中可使用,没有限制 ...

随机推荐

  1. [luogu4285 SHOI2008] 汉诺塔 (暴力,数学)

    传送门 Solution 强行猜测公式形如\(f_i=k\times f_{i-1}+b\),暴力求\(f_1,f_2,f_3\),剩下的递推就行 Code #include <cstdio&g ...

  2. 33.bulk json格式的理解

    bulk json格式的理解 一.常规格式 按常规理解,bulk中json格式可以是以下方式 [{ "action": { }, "data": { } }] ...

  3. SQLServer · BUG分析 · Agent 链接泄露分析(转载)

    背景 SQLServer Agent作为Windows服务提供给用户定期执行管理任务,这些任务被称为Job:考虑应用镜像的场景如何解决Job同步问题,AWS RDS的做法是不予理会,由用户维护Job, ...

  4. Problem 52

    Problem 52 It can be seen that the number, 125874, and its double, 251748, contain exactly the same ...

  5. python爬虫06 | 你的第一个爬虫,爬取当当网 Top 500 本五星好评书籍

    来啦,老弟 我们已经知道怎么使用 Requests 进行各种请求骚操作 也知道了对服务器返回的数据如何使用 正则表达式 来过滤我们想要的内容 ... 那么接下来 我们就使用 requests 和 re ...

  6. Git 基础教程 之 创建版本库

    一,选择一个合适的地方,创建空目录,下面两种方法都可 ①   手动新建 ②   使用命令: mkdir pythonwork 二,初始化,使目录变成Git可管理的仓库        执行: git i ...

  7. POJ 4046 Sightseeing

    Sightseeing Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID ...

  8. 只读事务(@Transactional(readOnly = true))的一些概念

    念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必要 ...

  9. SICP 习题1.16-1.19体会

    首先反思一下, 昨天做1.14的时候犯了一个严重错误.思维定式了,导致花了非常多无用功. 1.14的关键是要想到2个物理意义. 一个是广度优先, 也就是仅仅考虑问题递归树的第一层子数.那么必定有公式 ...

  10. leetcode || 56、 Merge Intervals

    problem: Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3], ...