Dynamic CRM 2013学习笔记(三十八)流程1 - 操作(action)开发与配置详解
这篇主要介绍操作:什么是操作、什么时候使用操作、如何创建以及如何调用
CRM 2013 里流程有4个类别:操作(action)、业务流程(business process flow)、对话(dialog)和工作流(workflow)。它们都是从 setting –> Process 进入,然后点击New按钮来创建:
这篇主要介绍操作:什么是操作、什么时候使用操作、如何创建以及如何调用
一、什么是操作
操作是CRM 2013 新增加的一个功能,用来扩展系统的标准功能。业务人员可以用它来实现业务逻辑,然后开发人员可以在系统事件里(比如update,create)来使用它。业务人员可以写业务逻辑,就像以前在工作流时一样。如果业务逻辑改变了,业务人员可以直接在操作里修改,而不需要开发人员的参与。 它可以针对某个实体,也可以是全局的(也就是不针对任何实体),也是在执行管道的30阶段执行,参与到数据库事物中,可以将多个步骤或者操作包含到操作中,支持输入和输出参数,支持在这个消息的Pre或者Post阶段调用其他的插件或者工作流,支持在C#或者JavaScript中调用它,但是它不支持在工作流中直接被调用,也不支持设定触发的范围,设置触发范围为组织级或者用户级。
二、什么时候使用操作
如果你想在一些条件下执行待定的一些步骤,比如一个case被打开多少天并且没有其它操作;我们能根据case打开的天数来实现业务逻辑,然后在case记录里执行它。我们可以发邮件到高级service manager,改变proirity,把case分配到队列里,所以的这些步骤都可以在一个流程里。在以前的版本里,我们用工作流来实现。
三、怎么创建操作
1. settings –> process, 点击New 按钮创建操作
2. 点击ok后,会弹出下面的界面:
3. 可以定义输入,输出参数,是否回滚等:
4. 添加步骤
- 发送邮件:
- 更新实体:
- 创建队列:
- 赋值:
最终效果图如下:
四、如何调用
1. 插件调用
消息里不是我们以前常用的update,create之类了。
- public class ActionsSample :IPlugin
- {
- string priority = string.Empty;
- public void Execute( IServiceProvider serviceProvider)
- {
- IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService( typeof( IPluginExecution Context));
- EntityReference caseRecord = context.InputParameters[" Target"] as EntityReference;
- EntityReference EscalatedBy = context.InputParameters[" EscalatedBy"] as EntityReference;
- priority = context.OutputParameters[" Priority"]. ToString(); }
- }
- }
也可以在update或create之类的消息里,用下面的方法调用操作:
- OrganizationRequest req = new OrganizationRequest("new_Escalat");
- req["EscalatedBy"] = new EntityReference("systemuser", context.InitiatingUserId);
- req["Target"] = new EntityReference(context.PrimaryEntityName, context.PrimaryEntityId);
- OrganizationResponse response = service.Execute(req);
2. JS调用
界面上添加一个按钮,然后调用下面的function:
- var requestXML = new XMLHttpRequest();
- requestXML.onreadystatechange = ShowResponse;
- function Escalate() {// function for the command bar
- var recordId = Xrm.Page.data.entity.getId(); var userId = Xrm.Page.context.getUserId();
- EscalateRequest( userId, recordId);
- }
- function EscalateRequest( EscalatedById, CaseId) {
- var postUrl = Xrm.Page.context.getClientUrl() + "/ XRMServices/ 2011/ Organization. svc/ web";
- // WebService Url var requestText = ""; requestText + = "< s:Envelope xmlns:s =\" http:// schemas.xmlsoap.org/ soap/ envelope/\" >";
- requestText + = " < s:Body >"; requestText + = " < Execute xmlns =\" http:// schemas.microsoft.com/ xrm/ 2011/ Contracts/ Services\" xmlns:i =\" http:// www.w3. org/ 2001/ XMLSchema-instance\" >";
- requestText + = " < request xmlns:a =\" http:// schemas.microsoft.com/ xrm/ 2011/ Contracts\" >";
- requestText + = " < a:Parameters xmlns:c =\" http:// schemas. datacontract.org/ 2004/ 07/ System.Collections.Generic\" >";
- requestText + = " < a:KeyValuePairOfstringanyType >"
- requestText + = " < c:key > EscalatedBy </ c:key >"
- requestText + = " < c:value i:type =\" a:EntityReference\" >"
- requestText + = " < a:Id >" + EscalatedById + "</ a:Id >"
- requestText + = " < a:LogicalName > systemuser </ a:LogicalName >"
- requestText + = " < a:Name i:nil =\" true\" />"
- requestText + = " </ c:value >"
- requestText + = " </ a:KeyValuePairOfstringanyType >"
- requestText + = " < a:KeyValuePairOfstringanyType >"
- requestText + = " < c:key > Target </ c:key >"
- requestText + = " < c:value i:type =\" a:EntityReference\" >"
- requestText + = " < a:Id >" + CaseId + "</ a:Id >"
- requestText + = " < a:LogicalName > incident </ a:LogicalName >"
- requestText + = " < a:Name i:nil =\" true\" />"
- requestText + = " </ c:value >"
- requestText + = " </ a:KeyValuePairOfstringanyType >"
- requestText + = " </ a:Parameters >"
- requestText + = " < a:RequestId i:nil =\" true\" />"
- requestText + = " < a:RequestName > new_Escalate </ a:RequestName >"
- requestText + = " </ request >"
- requestText + = " </ Execute >"
- requestText + = " </ s:Body >"
- requestText + = "</ s:Envelope >"
- requestXML.open(" POST", postUrl, true);// true is for async
- requestXML.setRequestHeader(" Accept", "application/ xml, text/ xml, */*");
- requestXML.setRequestHeader(" Content-Type", "text/ xml; charset = utf-8");
- requestXML.setRequestHeader(" SOAPAction", "http:// schemas.microsoft.com/ xrm/ 2011/ Contracts/ Services/ IOrganizationService/ Execute");
- requestXML.send( requestText); }
- function ShowResponse() {
- var x = requestXML.responseXML.getElementsByTagName(" a:KeyValuePairOfstringany Type");
- for (i = 0; i < x.length; i + +) {
- if (x[ i]. childNodes[ 0]. textContent = = "Priority")
- { alert(" The case has been assigned to " + x[ i]. childNodes[ 1]. textContent + " priority."); } }
- }