Dynamic CRM 2013學習筆記(三十八)流程1 - 操做(action)開發與配置詳解

CRM 2013 裏流程有4個類別:操做(action)、業務流程(business process flow)、對話(dialog)和工做流(workflow)。它們都是從 setting –> Process 進入,而後點擊New按鈕來建立:php

image

這篇主要介紹操做:什麼是操做、何時使用操做、如何建立以及如何調用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

image

 

2. 點擊ok後,會彈出下面的界面:學習

image 

3. 能夠定義輸入,輸出參數,是否回滾等:ui

image

4. 添加步驟

  • 發送郵件:

image

  • 更新實體:

image

 

  • 建立隊列:

image

 

  • 賦值:

image

 

最終效果圖以下:

image 

4、如何調用

1. 插件調用

消息裏不是咱們之前經常使用的update,create之類了。

image

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

 

 

 

 

 

 

Dynamic CRM 2013學習筆記 系列彙總

相關文章
相關標籤/搜索