Dynamics 365中的Client API form context (formContext)

適用於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對象

如下是一段使用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 對象模型

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

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

相關文章
相關標籤/搜索