这篇主要介绍操作:什么是操作、什么时候使用操作、如何创建以及如何调用

CRM 2013 里流程有4个类别:操作(action)、业务流程(business process flow)、对话(dialog)和工作流(workflow)。它们都是从 setting –> Process 进入,然后点击New按钮来创建:

image

这篇主要介绍操作:什么是操作、什么时候使用操作、如何创建以及如何调用

 

一、什么是操作

操作是CRM 2013 新增加的一个功能,用来扩展系统的标准功能。业务人员可以用它来实现业务逻辑,然后开发人员可以在系统事件里(比如update,create)来使用它。业务人员可以写业务逻辑,就像以前在工作流时一样。如果业务逻辑改变了,业务人员可以直接在操作里修改,而不需要开发人员的参与。 它可以针对某个实体,也可以是全局的(也就是不针对任何实体),也是在执行管道的30阶段执行,参与到数据库事物中,可以将多个步骤或者操作包含到操作中,支持输入和输出参数,支持在这个消息的Pre或者Post阶段调用其他的插件或者工作流,支持在C#或者JavaScript中调用它,但是它不支持在工作流中直接被调用,也不支持设定触发的范围,设置触发范围为组织级或者用户级。

 

二、什么时候使用操作

如果你想在一些条件下执行待定的一些步骤,比如一个case被打开多少天并且没有其它操作;我们能根据case打开的天数来实现业务逻辑,然后在case记录里执行它。我们可以发邮件到高级service manager,改变proirity,把case分配到队列里,所以的这些步骤都可以在一个流程里。在以前的版本里,我们用工作流来实现。

 

三、怎么创建操作

1. settings –> process, 点击New 按钮创建操作

image

 

2. 点击ok后,会弹出下面的界面:

image 

3. 可以定义输入,输出参数,是否回滚等:

image

4. 添加步骤

  • 发送邮件:

image

  • 更新实体:

image

 

  • 创建队列:

image

 

  • 赋值:

image

 

最终效果图如下:

image 

四、如何调用

1. 插件调用

消息里不是我们以前常用的update,create之类了。

image

  1. public class ActionsSample :IPlugin
  1. {
  1. string priority = string.Empty;
  1. public void Execute( IServiceProvider serviceProvider)
  1. {
  1. IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService( typeof( IPluginExecution Context));
  1. EntityReference caseRecord = context.InputParameters[" Target"] as EntityReference;
  1. EntityReference EscalatedBy = context.InputParameters[" EscalatedBy"] as EntityReference;
  1. priority = context.OutputParameters[" Priority"]. ToString(); }
  1.  
  1. }
  1. }

 

也可以在update或create之类的消息里,用下面的方法调用操作:

  1. OrganizationRequest req = new OrganizationRequest("new_Escalat");
  1.  
  1. req["EscalatedBy"] = new EntityReference("systemuser", context.InitiatingUserId);
  1.  
  1. req["Target"] = new EntityReference(context.PrimaryEntityName, context.PrimaryEntityId);
  1.  
  1. OrganizationResponse response = service.Execute(req);

 

 

2. JS调用

 

 

 

 

 

 

 

 

界面上添加一个按钮,然后调用下面的function:

  1. var requestXML = new XMLHttpRequest();
  1. requestXML.onreadystatechange = ShowResponse;
  1. function Escalate() {// function for the command bar
  1. var recordId = Xrm.Page.data.entity.getId(); var userId = Xrm.Page.context.getUserId();
  1. EscalateRequest( userId, recordId);
  1. }
  1.  
  1. function EscalateRequest( EscalatedById, CaseId) {
  1. var postUrl = Xrm.Page.context.getClientUrl() + "/ XRMServices/ 2011/ Organization. svc/ web";
  1. // WebService Url var requestText = ""; requestText + = "< s:Envelope xmlns:s =\" http:// schemas.xmlsoap.org/ soap/ envelope/\" >";
  1. requestText + = " < s:Body >"; requestText + = " < Execute xmlns =\" http:// schemas.microsoft.com/ xrm/ 2011/ Contracts/ Services\" xmlns:i =\" http:// www.w3. org/ 2001/ XMLSchema-instance\" >";
  1. requestText + = " < request xmlns:a =\" http:// schemas.microsoft.com/ xrm/ 2011/ Contracts\" >";
  1. requestText + = " < a:Parameters xmlns:c =\" http:// schemas. datacontract.org/ 2004/ 07/ System.Collections.Generic\" >";
  1. requestText + = " < a:KeyValuePairOfstringanyType >"
  1. requestText + = " < c:key > EscalatedBy </ c:key >"
  1. requestText + = " < c:value i:type =\" a:EntityReference\" >"
  1. requestText + = " < a:Id >" + EscalatedById + "</ a:Id >"
  1. requestText + = " < a:LogicalName > systemuser </ a:LogicalName >"
  1. requestText + = " < a:Name i:nil =\" true\" />"
  1. requestText + = " </ c:value >"
  1. requestText + = " </ a:KeyValuePairOfstringanyType >"
  1. requestText + = " < a:KeyValuePairOfstringanyType >"
  1. requestText + = " < c:key > Target </ c:key >"
  1. requestText + = " < c:value i:type =\" a:EntityReference\" >"
  1. requestText + = " < a:Id >" + CaseId + "</ a:Id >"
  1. requestText + = " < a:LogicalName > incident </ a:LogicalName >"
  1. requestText + = " < a:Name i:nil =\" true\" />"
  1. requestText + = " </ c:value >"
  1. requestText + = " </ a:KeyValuePairOfstringanyType >"
  1. requestText + = " </ a:Parameters >"
  1. requestText + = " < a:RequestId i:nil =\" true\" />"
  1. requestText + = " < a:RequestName > new_Escalate </ a:RequestName >"
  1. requestText + = " </ request >"
  1. requestText + = " </ Execute >"
  1. requestText + = " </ s:Body >"
  1. requestText + = "</ s:Envelope >"
  1. requestXML.open(" POST", postUrl, true);// true is for async
  1. requestXML.setRequestHeader(" Accept", "application/ xml, text/ xml, */*");
  1. requestXML.setRequestHeader(" Content-Type", "text/ xml; charset = utf-8");
  1. requestXML.setRequestHeader(" SOAPAction", "http:// schemas.microsoft.com/ xrm/ 2011/ Contracts/ Services/ IOrganizationService/ Execute");
  1. requestXML.send( requestText); }
  1. function ShowResponse() {
  1. var x = requestXML.responseXML.getElementsByTagName(" a:KeyValuePairOfstringany Type");
  1. for (i = 0; i < x.length; i + +) {
  1. if (x[ i]. childNodes[ 0]. textContent = = "Priority")
  1. { alert(" The case has been assigned to " + x[ i]. childNodes[ 1]. textContent + " priority."); } }
  1. }

 

 

 

 

 

 

Dynamic CRM 2013学习笔记 系列汇总

版权声明:本文为fengwenit原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/fengwenit/p/4301847.html