我有以下代码设置 onLoad 以在关联帐户标记为“服务监视”时在“发货”记录上生成横幅。该代码当前可以运行,但它会生成错误警报"unable to get property '0' of undefined or null reference"。当用户创建新的货件记录时会发生此错误,因为帐户字段尚无值。
如何配置代码以忽略帐户字段中的 NULL 值?
function checkServiceWatch() {
try{
var account = Xrm.Page.getAttribute("cmm_account").getValue();
var accountid = account[0].id;
var formattedGuid = accountid.replace("}", "");
accountid = formattedGuid.replace("{", "");
// alert("Accountid: " + accountid); // does that ID have brackets around it?
// alert("Request: " + Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accountid + ")?$select=cmm_servicewatch");
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accountid + ")?$select=cmm_servicewatch", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function()
应忽略正在创建的记录,但会在具有帐户值的现有货件上生成横幅。
汪汪一只猫
相关分类