如何使用JavaScript获取Dynamics 365中的字段值?
在浏览器控制台中,函数Xrm.Page()
返回undefined。
当我尝试获得像
Xrm.Page.getAttribute("new_city").getValue();
在浏览器控制台中收到错误:
无法获取未定义或空引用的属性“getValue”
答案 0 :(得分:0)
Xrm.Page()
可能不是一种存在的方法。请改为Xrm.Page
。
对于Xrm.Page.getAttribute("new_city")
,您确定:
答案 1 :(得分:0)
您的代码:
Xrm.Page.getAttribute("new_city").getValue();
应该可以。
确保您使用的名称与“字段属性”中显示的名称完全相同。
答案 2 :(得分:0)
可能的原因在其他答案中给出。
为避免错误,请始终使用null检查。
if(Xrm.Page.getAttribute("new_city") != null)
var city = Xrm.Page.getAttribute("new_city").getValue();
如果您在标题中使用此字段,请使用以下内容:
Xrm.Page.getAttribute("header_new_city").getValue();
如果您正在业务流程中使用此字段,请使用此字段:
Xrm.Page.getAttribute("header_process_new_city").getValue();
答案 3 :(得分:0)
有两种方法可以解决此问题
在“开发人员工具”窗口右上角的“目标”下拉列表中,切换到“客户端API包装器”。然后,您应该可以使用javascript代码访问表单。您的语法正确。
在代码的开头添加索引为0的帧
示例:
var city = frames[0].Xrm.Page.getAttribute('bah_city').getValue();
祝你好运!
答案 4 :(得分:0)