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."); } }
}