Dynamics 365中的Client API form context (formContext)


適用於Dynamics 365 for Customer Engagement apps 9.x版本。

 

本文是一篇翻譯,原文來源是微軟官方文檔

本文鏈接:https://www.cnblogs.com/hhelibeb/p/11042391.html 

 

概述

Client API form context (formContext)提供了對當前代碼運行的上下文中的form或對form上的item的引用,比如,一個quick view控件或者一個可編輯grid中的行。

在早期版本,全局的Xrm.Page對象用於代表form或form中的item。在9.0版本中,Xrm.Page對象過時了,你應該使用被傳入的運行上下文對象的getFormContext方法獲取相應的from的引用。

 

注意:formContext對象允許你創建通用的事件處理器,根據調用位置來對form或可編輯grid進行操作。詳見getFormContext (Client API reference)。從ribbon action的Javascript函數中獲取formContext和從scripting中獲取它的方式是不同的。更多信息:Form and grid context in ribbon actions.

使用formContext對象

以下是一段使用formContext對象的JS代碼,通過傳入的運行上下文(executionContext)獲取formContext對象,

function displayName(executionContext)
{
    var formContext = executionContext.getFormContext(); // get formContext

    var firstName = formContext.getAttribute("firstname").getValue(); 
    var lastName = formContext.getAttribute("lastname").getValue();
    console.log(firstName + " " + lastName);
}

(譯注:省略了原文中有關過時的Xrm.Page對象的部分)

formContext 對象模型

formContext對象下包含dataui對象,它們允許你通過編程方式操作數據和用戶界面元素。

data對象

data對象可用於訪問entity數據,也提供了管理form、business process flow控件中數據的方法。它包含以下對象:

Object Description
entity 提供方法來根據頁面的顯示的記錄檢索信息,也提供了save方法、以及包含form中全部屬性的集合。
process 提供方法檢索business process flow的屬性。

它也提供了一個用於訪問非entity綁定的控件的屬性集。詳見文章的稍后部分的 formContext對象模型中的集合

更多信息:formContext.data

UI對象

提供檢索UI信息的方法,包含from或grid的某些子組件的集合。它包含以下對象:

Object Description
formSelector        提供item集合,該集合可以用於查詢對當前用戶有效的form。可以使用navigate方法關閉當前form,並打開一個新的form。
navigation 不包含任何方法,提供通過item集合訪問item的能力。參考下一節。
process 提供在form上與business process flow控件交互的方法。

更多信息:formContext.ui

formContext對象模型中的集合

下面的表格描述了Xrm對象模型中的集合。關於集合的一般可用方法的信息,參看Collections (Client API reference).。

 

Collection Description
attributes

有2個對象包含attributes集合


- formContext.data.attributes: 用於訪問非entity綁定屬性。

- formContext.data.entity.attributescollection: 用於訪問在form中可用的entity。只對與添加到form上的字段對應的屬性可用。

controls

有3個對象包含controls集合


- formContext.ui.controls: 用於訪問form中出現的控件。

- formContext.data.entity.attribute.controls: 因為一個屬性也許會在表單上面有多個控件,該集合用於訪問它們。如果沒有為屬性添加多個控件,那么這個集合只會包含1個item.

- formContext.ui.tabs.sections.controls: 這個集合只包含在section中的控件。

formContext.data.process.stages                                                                          

formContext.data.process.steps

用於訪問business process flow中的stage和step集合。可以從集合中添加和刪除item。
formContext.ui.formselector.items                   當一個entity有多個form的時候,可以通過安全角色關聯這些form。當用戶的安全角色允許他訪問不止一個form時,該集合可以用於訪問對於當前用戶可用的各個form。
formContext.ui.navigation.items The formContext.ui.navigation.itemscollection 用於訪問通過form編輯器定義的導航項。用戶通過command bar來訪問那些導航項。
formContext.ui.quickForms

用於訪問所有quick view控件和它在Customer Enagagement forms中的上級控件。

formContext.ui.tabs 可以通過一或多個tab來組織form。這個集合用於訪問tab.
formContext.ui.tabs.sections              tab中可以包含一或多個section。該集合用於訪問section。

相關主題

getFormContext method

getGlobalContext method

Execution context methods

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM