How to access controls from a console

寵の児 提交于 2019-12-03 16:36:49

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();

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.

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

meh

I know this is a kinda old thread, but if you still getting that 'object doesn't support property..' error when executing the command from console, IE F12; try calling it from the frame i.e

frames[0].Xrm.Page.getAttribute("controlId").getValue();

In CRM 2013 it is a little different

frames[1].Xrm.Page

It's kind of tough to detect the frames across different browsers, so this little javascript can help you out:

for(var i=0;i<5;i++) //loop through 0 to 4
    if(frames[i].Xrm.Page.ui != undefined) //check if undefined    
    {
        Xrm = frames[i].Xrm;  //assign Xrm
        console.info("~: Xrm updated with frame " + i + " :~"); //show info
        break; //breakout the loop
    }

What it does ?

What it's basically doing is to loop through 0-5 to find frame where Xrm.Page.ui is not undefined, once it gets it it assigns it to the Xrm and breaks the loop.

How to use ?

To use it just copy/paste and run in the browser console once per session then after you can run/test all your Xrm codes form the browser console.

Daryl

This works for me Xrm.Page.getControl("controlId"). It's just a shortcut for what you have already though...cant-disable-set-to-read-only-protect-gray-out-etc-a-field

A reason some people need this information is to access their own code. If you need to access your own methods from the console, in 2011, any global methods (or namespaces) in your javascript were also in forms[0]. Obviously, this is a bad idea, just from a naming standpoint. In forms v6+ any global objects or functions are in an object called customScriptsFrame inside frames[0] (or presumably whichever frame the Xrm is found).

frames[0].customScriptsFrame.myFunctionName();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!