適用於Dynamics 365 for Customer Engagement apps 9.x版本。html
本文是一篇翻譯,原文來源是微軟官方文檔。編程
本文連接:http://www.javashuo.com/article/p-ytqdlxbx-ds.html api
Client API form context (formContext)提供了對當前代碼運行的上下文中的form或對form上的item的引用,好比,一個quick view控件或者一個可編輯grid中的行。安全
在早期版本,全局的Xrm.Page對象用於表明form或form中的item。在9.0版本中,Xrm.Page對象過期了,你應該使用被傳入的運行上下文對象的getFormContext方法獲取相應的from的引用。app
注意:formContext對象容許你建立通用的事件處理器,根據調用位置來對form或可編輯grid進行操做。詳見getFormContext (Client API reference)。從ribbon action的Javascript函數中獲取formContext和從scripting中獲取它的方式是不一樣的。更多信息:Form and grid context in ribbon actions.編輯器
如下是一段使用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對象的部分)ui
formContext對象下包含data和ui對象,它們容許你經過編程方式操做數據和用戶界面元素。spa
data對象可用於訪問entity數據,也提供了管理form、business process flow控件中數據的方法。它包含如下對象:翻譯
Object | Description |
---|---|
entity | 提供方法來根據頁面的顯示的記錄檢索信息,也提供了save方法、以及包含form中所有屬性的集合。 |
process | 提供方法檢索business process flow的屬性。 |
它也提供了一個用於訪問非entity綁定的控件的屬性集。詳見文章的稍後部分的 formContext對象模型中的集合。
更多信息:formContext.data
提供檢索UI信息的方法,包含from或grid的某些子組件的集合。它包含如下對象:
Object | Description |
---|---|
formSelector | 提供item集合,該集合能夠用於查詢對當前用戶有效的form。能夠使用navigate方法關閉當前form,並打開一個新的form。 |
navigation | 不包含任何方法,提供經過item集合訪問item的能力。參考下一節。 |
process | 提供在form上與business process flow控件交互的方法。 |
更多信息:formContext.ui
下面的表格描述了Xrm對象模型中的集合。關於集合的通常可用方法的信息,參看Collections (Client API reference).。
Collection | Description |
---|---|
attributes | 有2個對象包含attributes集合
|
controls | 有3個對象包含controls集合
|
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。 |