创建一个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中

原文地址:https://www.cnblogs.com/TheMiao/p/10834561.html

时间: 2024-08-28 00:29:50

创建一个dynamics CRM workflow (四) - Development of Custom Workflows的相关文章

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

我们打开plugin registeration tool. 注册一个新的assembly. custom workflow 和 plugin注册的方法还有些不同. 这一步custom workflow就结束了. 因为custom workflow是通过business workflow来使用的 下一步,我们需要找到之前创建好的 processes 在process中, 让我们添加写好的workflow. 添加custom workflow之后, 让我们点击set properties. 然后给

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

我们之前创建的plugin都是使用default的 run in User's Context. 理解就是使用正在登陆的security context用户信息 那有个问题,如果当前用户的security role没有相应的权限访问功能,我们就要安排一个新的用户 e.g. admin来记录信息而非当前用户. 让我们在registration tool更新TaskCreate class之后再CRM中打开新建Contacts. 我们可以打开activities发现follow up 里用户更改为在

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

Isolation Mode 也被称作为Plugin Trust CRM里面有两种plugin trust / isolation mode 1. Full Trust 只在OP系统中可使用,没有限制 plugin 挂掉之后会影响到CRM服务器运行. 可以访问服务器文件 2. Partial Trust or Sandbox 可在OP系统和online系统中使用 运行在特定的区域中,当plugin crash之后, CRM系统不会随之崩盘 Plugin 在secure layer底下运行, 并且

利用django创建一个投票网站(四)

创建你的第一个 Django 项目, 第四部分 这一篇从第三部分(zh)结尾的地方继续讲起.我们将继续编写投票应用,专注于简单的表单处理并且精简我们的代码. 编写一个简单的表单 让我们更新一下在上一个教程中编写的投票详细页面的模板("polls/detail.html"),让它包含一个 HTML <form>元素: <!--- polls/template/polls/detail.html --> <h1>{{ question.question_

创建一个dynamics 365 CRM online plugin (四) (Not finished)

开始之前,我们要确认一下 Plugin 的 pipeline. PreValidation -> PreOperation -> Server Side System Main Event-> PostOperation PreValidation 是在security check 之前, 通常会用来加载外部数据和用户不相关的内容.PreOperation 是在security check 之后, 通常会用来做一系列的功能.PostOperation 是在System Main Even

创建一个dynamics 365 CRM online plugin (五) - Images in Plugin

Snapshots of the primary entity's attributes from database before(pre) and after (post) the core platform operation. 怎么理解这句话呢 简单的我们可以理解PreOperation与PostOperation的 entity中数据的镜像. 使用Pre-Entity镜像的一些案例: 1. 如果你需要对original data在modification之前做使用. 2. 如果你需要fo

怎样创建一个dynamics 365 CRM online plugin (二)

Golden Rules 1. Platform only passes Entity attributes to Plugin that has change of data. 2. If the user does not enter any value into attribute, the attribute is not avaible in AttributeCollection of Entity. 3. Always check if attribute is present i

创建一个dynamics 365 CRM online plugin (八) - 使用Shared Variables 在plugins 之前传递data

CRM 可以实现plugin之前的值传递. 我们可以使用SharedVariables 把值在plugin之间传递 实现plugins之间的传递非常简单,我们只需要用key value pair来配对传递. 读取的时候用key来获取相应key的value try { /* * SharedVariabls can share the variabls to different plugins * SharedVariabls will only work under same pipeline

创建一个dynamics 365 CRM online plugin (十二) - Asynchronous Plugins

这篇是plugin的终结. 通过之前的11期我们应该发现了plugin其实学习起来不难. async plugin 是把plugin的功能async run起来. e.g.  我们之前做过的preOperation的plugin会马上执行并且马上有数据显示在entity中. 但是async plugin会在async 形式下run, 使用场景是有很大的计算量或者处理量会导致CRM server进程被block 掉. 我们可以在plugin registeration tool中选择是否需要asy