我試圖從已插入到CRM 2011中的窗體的HTML Web資源中訪問Xrm.Page.data對象。但是,關於如何嘗試訪問Xrm實體,我發現它未定義或者Xrm.Page.data爲空。對於網絡資源的代碼如下:無法從CRM 2011中的HTML Web資源中訪問Xrm.Page.data
<!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>
我已經從一個JavaScript函數,該函數在一個窗體事件觸發(如表一庫的一部分內訪問Xrm.Page.data成功。加載)。只是當它嵌入在我遇到這個問題的窗體上的HTML Web資源中時。任何人都可以解釋我做錯了什麼,如果真的有辦法以這種方式訪問Xrm.Page.data我想要做什麼?
謝謝。
另外窩rks for Mscrm.CrmUri – GPGVM
我有同樣的問題。我在Chrome 37中運行這個。我有一個web資源在實體表單的IFrame中顯示。我嘗試了所有組合,但仍無法使用Xrm對象。幫助將不勝感激! –