【发布时间】:2020-02-27 11:29:41
【问题描述】:
我正在尝试创建一个 javascript 来运行“onPageLoad”。 我要运行它的实体是联系人,在页面加载(联系人页面)时,我想检查与联系人关联的帐户是否属于“potential_client”类型。
因此,如果帐户的类型为“potential_client”,我想锁定联系人页面上的字段,例如 名字、姓氏、电子邮件、地址
编辑 - 我的尝试
function onPageLoad(){
var accountid = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id;
Xrm.WebApi.retrieveRecord("account", accountid, "?$select=customertypecode").then(
function success(result) {
if (result != null) {
if (result.customertypecode == 1 || result.customertypecode == 3) {
Xrm.Page.ui.controls.get("firstname").setDisabled(true);
Xrm.Page.ui.controls.get("lastname").setDisabled(true);
Xrm.Page.ui.controls.get("emailaddress1").setDisabled(true);
}
}
},
function(error) {
alert(error.message);
)
}
错误: 无法读取 null 的属性 setDisabled
编辑 2 所以我发现 firstname 和 lastname 行用那个错误破坏了脚本,我认为这是因为它们已经锁定在配置中,所以我把它拿出来,现在它们可以被禁用,当我再次添加这些行时,脚本中断在 2 行中出现相同的错误“无法读取 null 的属性 setDisabled”。知道为什么吗?
【问题讨论】:
-
所以你开始写代码了?显示一些尝试
-
@ArunVinoth 我尝试编辑问题
-
似乎 "Xrm.Page.ui.controls.get("firstname")" 正在返回 null,这很奇怪,因为我在联系表单上运行它。
-
附言。刚刚插入了这个警报(Xrm.Page.getAttribute("firstname").getValue());我得到了正确的值“teste”
-
可能是由于全名复合控件引起的问题..检查这种可能性