gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:43:09 25 4
gpt4 key购买 nike

我正在尝试从插入到 CRM 2011 中的表单中的 HTML Web 资源中访问 Xrm.Page.data 对象。但是,根据我尝试访问 Xrm 实体的方式,我发现它是未定义或 Xrm.Page.data 为空。 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>

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

谢谢。

最佳答案

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

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

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

window.parent.Xrm.Page.context...

喜欢

alert(window.parent.Xrm.Page.data.entity.attributes.get("new_field_i_want").getValue());

来自您的示例代码。

关于javascript - 无法从 CRM 2011 中的 HTML Web 资源访问 Xrm.Page.data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21790176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com