CRM 2013 里流程有4个类别:操做(action)、业务流程(business process flow)、对话(dialog)和工做流(workflow)。它们都是从 setting –> Process 进入,而后点击New按钮来建立:php
这篇主要介绍操做:什么是操做、何时使用操做、如何建立以及如何调用html
1、什么是操做web
操做是CRM 2013 新增长的一个功能,用来扩展系统的标准功能。业务人员能够用它来实现业务逻辑,而后开发人员能够在系统事件里(好比update,create)来使用它。业务人员能够写业务逻辑,就像之前在工做流时同样。若是业务逻辑改变了,业务人员能够直接在操做里修改,而不须要开发人员的参与。 它能够针对某个实体,也能够是全局的(也就是不针对任何实体),也是在执行管道的30阶段执行,参与到数据库事物中,能够将多个步骤或者操做包含到操做中,支持输入和输出参数,支持在这个消息的Pre或者Post阶段调用其余的插件或者工做流,支持在C#或者JavaScript中调用它,可是它不支持在工做流中直接被调用,也不支持设定触发的范围,设置触发范围为组织级或者用户级。数据库
2、何时使用操做app
若是你想在一些条件下执行待定的一些步骤,好比一个case被打开多少天而且没有其它操做;咱们能根据case打开的天数来实现业务逻辑,而后在case记录里执行它。咱们能够发邮件到高级service manager,改变proirity,把case分配到队列里,因此的这些步骤均可以在一个流程里。在之前的版本里,咱们用工做流来实现。async
3、怎么建立操做ide
1. settings –> process, 点击New 按钮建立操做post
2. 点击ok后,会弹出下面的界面:学习
3. 能够定义输入,输出参数,是否回滚等:ui
4. 添加步骤
最终效果图以下:
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."); } }
}