//商机界面上的创建沟通计划按钮响应函数
function createCommunicationplan() {
//获取创建沟通计划的数据
//拜访客户属性
var productlineValue = "",
customertype;
var productline = Xrm.Page.getAttribute("new_accountproductline").getValue();
if(productline != null && productline != "") {
productlineValue = productline[0].name;
}
if(productlineValue == "非华为客户选项") {
customertype = 1;
} else {
customertype = 0;
}
//产品线
var productlineId = getLookupValue("new_accountproductline");
//子产品线
var subproductlineId = getLookupValue("new_accountsubproductline");
//PDUSDU
var pdusduId = getLookupValue("new_accountpdusdu");
//客户全称
var parentaccountId = getLookupValue("parentaccountid");
//商机名称
var oppId = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");
//定义创建沟通计划的数据
var planData = {
"new_customertype": customertype,
"new_nonhwcustomer@odata.bind": "/accounts(" + parentaccountId + ")",
"new_productline@odata.bind": "/new_accounthws(" + productlineId + ")",
"new_subproductline@odata.bind": "/new_accounthws(" + subproductlineId + ")",
"new_pdusdu@odata.bind": "/new_accounthws(" + pdusduId + ")",
"new_regardingopp@odata.bind": "/opportunities(" + oppId + ")"
}
//创建沟通计划记录
Xrm.WebApi.createRecord("new_communicationplan", planData).then(
function success(result) {
//打开创建的沟通计划
var windowOptions = {
openInNewWindow: true
};
Xrm.Utility.openEntityForm("new_communicationplan", result.id, null, windowOptions);
},
function(error) {
//创建沟通计划报错
Xrm.Utility.alertDialog("Error :" + error.message, null);
}
);
}
//获取查找类型字段的id
function getLookupValue(fieldName) {
var value = "";
var lookupValue = Xrm.Page.getAttribute(fieldName).getValue();
if(lookupValue != null && lookupValue != "") {
value = lookupValue[0].id.replace("{", "").replace("}", "");
}
return value;
}