如何在Dynamics 365 9.0的Ribbon命令中获取formContext [英] How to get formContext in Ribbon command of Dynamics 365 9.0
问题描述
在Dynamics 365 9.0中,有关如何访问表单属性和控件的变化很大-代替 Xrm.Page
命名空间,我们应该传递 executionContext
到一个函数,并使用 getFormContext()
函数获取 formContext
。
但是我还没有弄清楚如何正确访问 formContext $> code>在功能区中调用。该文档说,这应该非常简单:
因此,它看起来像某种形式的形式,但可能与formContext无关(我假设如果从记录列表中调用功能区,则该项目可以是网格类型或类似的类型)
按照
因此,如果将PrimaryControl作为第二个参数传递给这样的命令函数,则可以使用
arguments [1] .getAttribute(…)
In Dynamics 365 9.0 there was quite a big change regarding how to access form attributes and controls - instead of Xrm.Page
namespace, we should pass executionContext
to a function and get formContext
using getFormContext()
function. This is working fine and I had never a problem with using this approach.
However I did not figured out yet how to properly access formContext
in functions that are called from Ribbon. The documentation says that this should be really straightforward:
function myFunction(executionContext) {
var formContext = executionContext.getFormContext();
var focusFieldValue = formContext.ui.controls.get(PrimaryControlId).getAttribute().getValue();
}
But it does not say how to pass executionContext
to Ribbon function. In normal functions there is a checkbox "Pass execution context as first parameter" but what about Ribbon functions? There are parameters that we can pass into these functions, but they are simply GUID of selected records, or type of selected record or even a list of objects but I could not find in documentation, if there is a parameter equal to executionContext
. Has anybody already solved this problem?
Also I know that I can use Xrm.Page and it will work (for now at least...) but I would like to know, how it can be done using the latest guidelines in version 9.0
Update 1:
As per Scott's suggestion and this article i passed PrimaryControl to my Ribbon command but unfortunately, the argument is of type Mscrm.FormControlLite
and it does not have getAttribute
function or any function that would allow to access the formContext (at least I don't see anything useful). Some screenshot from Developer tools:
So it looks like a form representation of some kind, but is probably not related to formContext (I assume that if a Ribbon would be called from a list of records, this item can be of type of grid or something like that)
As per https://docs.microsoft.com/en-us/dynamics365/get-started/whats-new/customer-engagement/important-changes-coming#some-client-apis-are-deprecated you pass it as the PrimaryControl parameter.
So if you pass the PrimaryControl as the second parameter to a command function like this you can use
arguments[1].getAttribute(…)
这篇关于如何在Dynamics 365 9.0的Ribbon命令中获取formContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!