如何从控制台访问控件

问题描述:

我试图从控制台执行以下命令。

I tried to execute the following command from the console.

var subject = Xrm.Page.ui.controls.get("subject");

这是我在插入CRM的网络资源中使用的确切语法。但是,我只收到一条错误消息,内容为无法获取未定义或空引用的属性控件。

That's the exact syntax I'm using in the web resource that I'm plugging in to CRM. However, I only got an error message saying that "unable to get property 'controls' of undefined or null reference".

我确实理解该消息。我想知道的是两个方面。

I do understand the message. What I want to know is two-fold.


  1. 从控制台( F12 )到

  2. 为什么它不能像我那样工作? ui 是从哪里来的?

  1. What syntax will work from the console (F12) to refer to the stuff on the screen?
  2. Why doesn't it work the way I did? Where doesn ui come from?

我检查了可以同时引用两个 Xrm Crm.Page ,但 ui 显然是 null (当我打印出 Page的内容时会列出 em>,但设置为 null )。

I've checked that I can refer to both Xrm and Crm.Page but apparently ui is null (it's listed when I print out the contents of Page but sett to null).

除了@Daryl所说的,我还可以另外,我使用了不同的语法。由于某种原因,我也不让他工作。可能与不同的浏览器版本有关。如果您仍然无法使用它,则尝试执行此操作(尽管我必须承认他的短一些=更好)。

In addition to what @Daryl said, I can add that I use different syntax. For some reason, I don't get his to work either. Might have to do with different browser version or something. Instead try to execute this, if you still can't get it to work (although I must admit that his is shorter = better).

Xrm.Page.getAttribute("lastname").getValue();

姓氏部分在一分钟前创建了实体 Contact 。我只是将一个断点放在执行 onchange 的脚本中,当断点时,我在控制台上输入了上面的命令。

The lastname parts is tested a minute ago on creation of an instance of entity Contact. I just put in a breakpoint inside a script that is executed onchange and while broken-pointed, I entered the command above to the console.

如果这两种方法都不适合您,则说明您的CRM或浏览器存在一些奇怪的问题。

If neither approach works for you, you've got some weird problem with your CRM or browser.