无法从CRM 2011中的HTML Web资源中访问Xrm.Page.data

sev*_*als 6 html javascript dynamics-crm-2011

我正在尝试从我已插入到CRM 2011中的表单的HTML Web资源中访问Xrm.Page.data对象.但是,根据我尝试访问Xrm实体的方式,我发现它未定义或者Xrm.Page.data为null.Web资源的代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">

function OpenMyApp(e){
    alert('Xrm defined: ' + (typeof Xrm != 'undefined'));
        // The line above returns the string 'Xrm defined: false'

    alert('window.top.opener.parent.Xrm defined: ' + (typeof window.top.opener.parent.Xrm != 'undefined'));
        // The line above returns the string 'window.top.opener.parent.Xrm defined: true'


    alert('frames[0].Xrm defined: ' + (typeof frames[0].Xrm != 'undefined'));
        // the line above will actually throw an error and stop the script, because the frames collection is empty. 

    alert(window.top.opener.parent.Xrm.Page.data);
        // the line above returns null. 

    // var myId = Xrm.Page.data.entity.attributes.get("new_field_i_want").getValue();
        // The line above is what I would like to see work. 

    e.preventDefault();
 }
</script>

</head>
<body>
<a onClick="OpenMyApp(event);" href="#">My Link</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我已经从JavaScript函数中成功访问了Xrm.Page.data,该函数是触发表单事件的库的一部分(例如,Form.Load).它只是当它嵌入到我遇到此问题的表单上的HTML Web资源中时.任何人都可以解释我做错了什么,如果有一种方法以我想做的方式访问Xrm.Page.data?

谢谢.

And*_*nko 13

尝试使用以下语法访问Xrm:

window.parent.Xrm.Page.getAttribute()...

window.parent.Xrm.Page.getControl()...

window.parent.Xrm.Page.context...
Run Code Online (Sandbox Code Playgroud)

喜欢

alert(window.parent.Xrm.Page.data.entity.attributes.get("new_field_i_want").getValue());
Run Code Online (Sandbox Code Playgroud)

从您的示例代码.