Microsoft Dynamics 2016 - Javascript 横幅
Microsoft Dynamics 2016 - Javascript Banner
我想利用 Xrm.Page.ui.setFormNotification
在 Shipment 记录的顶部显示横幅。此横幅只会针对 Shipments 显示,其中相关实体帐户分类为 "Service Watch"。
我是 Javascript 的新手,所以我有点不知道如何从记录的相关实体中提取值以供使用。
Xrm.Page.ui.setFormNotification("This Account is currently under Service Watch", "WARNING")
编辑:代码有效;
function checkServiceWatch() {
try{
var account = Xrm.Page.getAttribute("cmm_account").getValue();
var accountid = account[0].id;
var formattedGuid = accountid.replace("}", "");
accountid = formattedGuid.replace("{", "");
"/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()
{
if (this.readyState === 4)
{
req.onreadystatechange = null;
if (this.status === 200)
{
var result = JSON.parse(this.response);
var serviceWatch = result["cmm_servicewatch"];
// alert("serviceWatch: " + serviceWatch);
if(serviceWatch) //set notification
{
Xrm.Page.ui.setFormNotification("This Account is currently under Service Watch","WARNING","1");
} // else
// {
// //Xrm.Page.ui.clearFormNotification("1");
// }
}
else
{
Xrm.Utility.alertDialog("Status: " + this.status + ", Text: " + this.statusText);
}
}
};
req.send();
}
catch (err) {
alert("ServiceWatchCheckRibbon | checkServiceWatch " + err.message);
}
}
您必须在加载表单时查询帐户查找记录,以提取显示 "Service watch" 的额外属性,如果是,则显示通知横幅。
您可以参考 this community thread 并按原样使用示例代码,或者根据您的 CRM 版本 Xrm.Webapi
方法来完成此操作。
function checkAccount(){
var accountid = Xrm.Page.data.entity.attributes.get("new_parentaccount").getValue()[0].id;
if (accountid.startsWith("{") && accountid.endsWith("}"))
{
accountid = accountid.slice(1, accountid.length - 1);
}
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accountid + ")?$select=new_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() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200)
{
var result = JSON.parse(this.response);
var serviceWatch = result["new_servicewatch"];
if(serviceWatch) //set notification
{
Xrm.Page.ui.setFormNotification("This Account is currently under Service Watch","WARNING","1");
} else
{
//Xrm.Page.ui.clearFormNotification("1");
}
}
else
{
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
我想利用 Xrm.Page.ui.setFormNotification
在 Shipment 记录的顶部显示横幅。此横幅只会针对 Shipments 显示,其中相关实体帐户分类为 "Service Watch"。
我是 Javascript 的新手,所以我有点不知道如何从记录的相关实体中提取值以供使用。
Xrm.Page.ui.setFormNotification("This Account is currently under Service Watch", "WARNING")
编辑:代码有效;
function checkServiceWatch() {
try{
var account = Xrm.Page.getAttribute("cmm_account").getValue();
var accountid = account[0].id;
var formattedGuid = accountid.replace("}", "");
accountid = formattedGuid.replace("{", "");
"/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()
{
if (this.readyState === 4)
{
req.onreadystatechange = null;
if (this.status === 200)
{
var result = JSON.parse(this.response);
var serviceWatch = result["cmm_servicewatch"];
// alert("serviceWatch: " + serviceWatch);
if(serviceWatch) //set notification
{
Xrm.Page.ui.setFormNotification("This Account is currently under Service Watch","WARNING","1");
} // else
// {
// //Xrm.Page.ui.clearFormNotification("1");
// }
}
else
{
Xrm.Utility.alertDialog("Status: " + this.status + ", Text: " + this.statusText);
}
}
};
req.send();
}
catch (err) {
alert("ServiceWatchCheckRibbon | checkServiceWatch " + err.message);
}
}
您必须在加载表单时查询帐户查找记录,以提取显示 "Service watch" 的额外属性,如果是,则显示通知横幅。
您可以参考 this community thread 并按原样使用示例代码,或者根据您的 CRM 版本 Xrm.Webapi
方法来完成此操作。
function checkAccount(){
var accountid = Xrm.Page.data.entity.attributes.get("new_parentaccount").getValue()[0].id;
if (accountid.startsWith("{") && accountid.endsWith("}"))
{
accountid = accountid.slice(1, accountid.length - 1);
}
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accountid + ")?$select=new_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() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200)
{
var result = JSON.parse(this.response);
var serviceWatch = result["new_servicewatch"];
if(serviceWatch) //set notification
{
Xrm.Page.ui.setFormNotification("This Account is currently under Service Watch","WARNING","1");
} else
{
//Xrm.Page.ui.clearFormNotification("1");
}
}
else
{
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}