var f1 = ["new_source", "new_settlement", "new_amountofsettlement", "new_traineename", "new_company"];
var f2 = ["new_settlementtype", "new_contact", "new_amountofsettlement", "new_company"];
var f3 = ["new_noofmodule"];
var f4 = ["new_company"];
var f5 = ["new_orderno"];
var f6 = ["new_contact", "new_company"];
var f0 = ["new_orderno", "new_contractno"];
var f21 = ["new_settlement", "new_source", "new_traineename"];
var f12 = ["new_settlementtype"];
var f41 = ["new_source", "new_settlement", "new_amountofsettlement", "new_traineename"];
var f61 = ["new_source", "new_settlement", "new_amountofsettlement", "new_traineename"];
var f007 = ["new_contractno"];
var f111 = ["new_revenue"];
//onload
function OnLoad() {
//设置选项卡的显隐性
SetDetailTabVisible();
//if (Xrm.Page.ui.getFormType() != 1) {
//设置card view
SetCardView();
//设置合同view
SetContractView();
LockOrderField();
SetOrderFilterByType();
// }
}
//点击扣费
function ChargeAction() {
Xrm.Page.getAttribute("new_statusofsettlement").setValue(2);
Xrm.Page.getAttribute("new_statusofsettlement").setSubmitMode("always");
Xrm.Page.data.entity.save();
}
//设置选项卡显隐性
function SetDetailTabVisible() {
var oType = Xrm.Page.getAttribute("new_orderitemtype").getValue();
if (oType == 1) //1、公开课 2、内训 3、在线 4、人才测评 5、咨询 6、国际项目 7、复合式培训 8、虚拟课堂-公开课 9、虚拟课堂-内训 10、培训管理-服务 11、接力课程
{
Xrm.Page.ui.tabs.get("tab_pd").setVisible(true);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(false);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(false);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(false);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(false);
Xrm.Page.ui.tabs.get("tab_International").setVisible(false);
//设置必填字段
SetLevel(1, f1);
SetLevel(1, f0);
SetLevel(2, f3);
SetLevel(2, f12);
if (Xrm.Page.getAttribute("new_settlement").getValue() == 2 || Xrm.Page.getAttribute("new_settlement").getValue() == 4 || Xrm.Page.getAttribute("new_settlement").getValue() == 5) {
SetLevel(2, f007);
}
}
//2022-2-11 brian 新增
else if (oType == 8) //1、公开课 2、内训 3、在线 4、人才测评 5、咨询 6、国际项目 7、复合式培训 8、虚拟课堂-公开课 9、虚拟课堂-内训 10、培训管理-服务 11、接力课程
{
Xrm.Page.ui.tabs.get("tab_pd").setVisible(true);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(false);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(false);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(false);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(false);
Xrm.Page.ui.tabs.get("tab_International").setVisible(false);
//设置必填字段
SetLevel(1, f1);
SetLevel(1, f0);
SetLevel(2, f3);
SetLevel(2, f12);
if (Xrm.Page.getAttribute("new_settlement").getValue() == 2 || Xrm.Page.getAttribute("new_settlement").getValue() == 4 || Xrm.Page.getAttribute("new_settlement").getValue() == 5) {
SetLevel(2, f007);
}
}
else if (oType == 9) {
Xrm.Page.ui.tabs.get("tab_pd").setVisible(false);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(true);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(false);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(false);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(false);
Xrm.Page.ui.tabs.get("tab_International").setVisible(false);
//设置必填字段
SetLevel(1, f0);
SetLevel(1, f2);
SetLevel(2, f21);
SetLevel(2, f3);
}
//以上2022-2-11 brian 新增
else if (oType == 2 || oType == 7) {
Xrm.Page.ui.tabs.get("tab_pd").setVisible(false);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(true);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(false);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(false);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(false);
Xrm.Page.ui.tabs.get("tab_International").setVisible(false);
//设置必填字段
SetLevel(1, f0);
SetLevel(1, f2);
SetLevel(2, f21);
SetLevel(2, f3);
}
else if (oType == 3) {
Xrm.Page.ui.tabs.get("tab_pd").setVisible(false);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(false);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(true);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(false);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(false);
Xrm.Page.ui.tabs.get("tab_International").setVisible(false);
//设置必填字段
SetLevel(1, f0);
SetLevel(1, f3);
SetLevel(2, f1);
SetLevel(1, f12);
SetLevel(1, f111);
}
else if (oType == 4) {
Xrm.Page.ui.tabs.get("tab_pd").setVisible(false);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(false);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(false);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(true);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(false);
Xrm.Page.ui.tabs.get("tab_International").setVisible(false);
//设置必填字段
SetLevel(1, f0);
SetLevel(1, f4);
SetLevel(2, f41);
SetLevel(2, f3);
SetLevel(2, f12);
SetLevel(2, f007);
}
else if (oType == 5) {
Xrm.Page.ui.tabs.get("tab_pd").setVisible(false);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(false);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(false);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(false);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(true);
Xrm.Page.ui.tabs.get("tab_International").setVisible(false);
//设置必填字段
SetLevel(1, f5);
SetLevel(2, f1);
SetLevel(2, f12);
SetLevel(2, f3);
SetLevel(2, f007);
}
else if (oType == 6 || oType == 10) {
Xrm.Page.ui.tabs.get("tab_pd").setVisible(false);
Xrm.Page.ui.tabs.get("tab_inhouse").setVisible(false);
Xrm.Page.ui.tabs.get("tab_elearning").setVisible(false);
Xrm.Page.ui.tabs.get("tab_evaluationorder").setVisible(false);
Xrm.Page.ui.tabs.get("tab_Consult").setVisible(false);
Xrm.Page.ui.tabs.get("tab_International").setVisible(true);
//设置必填字段
SetLevel(1, f0);
SetLevel(1, f6);
SetLevel(2, f61);
SetLevel(2, f12);
SetLevel(2, f3);
SetLevel(2, f007);
}
OnSave();
}
//设置字段required level 1-必填 2-none
function SetLevel(c, f) {
if (c == 1) {
for (var i = 0; i < f.length; i++) {
Xrm.Page.getAttribute(f[i]).setRequiredLevel("required");
}
}
if (c == 2) {
for (var i = 0; i < f.length; i++) {
Xrm.Page.getAttribute(f[i]).setRequiredLevel("none");
}
}
}
//带出
function TakeCardInfo() {
//debugger;
var cardRe = Xrm.Page.getAttribute("new_card").getValue();
var card = CRK.Retrieve("new_discountcard", cardRe[0].id, new Array("new_PDofRemain", "new_GiftPDofRemain", "new_PricePD", "new_UnitePriceforUCardOC", "new_UnitePriceforUCardInhouse", "new_UnitePriceforUCardElearning"));
var type = Xrm.Page.getAttribute("new_orderitemtype").getValue();
var settlemntType = Xrm.Page.getAttribute("new_settlementtype").getValue();
var settlement = Xrm.Page.getAttribute("new_settlement").getValue();
if (type == 1) {
if (settlement == 2) {
Xrm.Page.getAttribute("new_availablepd").setValue(card.new_PDofRemain);
Xrm.Page.getAttribute("new_availablefreepd").setValue(card.new_GiftPDofRemain);
Xrm.Page.getAttribute("new_price").setValue(card.new_PricePD.Value);
Xrm.Page.getAttribute("new_availablepd").setSubmitMode("always");
Xrm.Page.getAttribute("new_availablefreepd").setSubmitMode("always");
Xrm.Page.getAttribute("new_price").setSubmitMode("always");
}
else if (settlement == 3) {
Xrm.Page.getAttribute("new_price").setValue(card.new_UnitePriceforUCardOC.Value);
Xrm.Page.getAttribute("new_price").setSubmitMode("always");
}
}
else if (type == 2) {
if (settlemntType == 2) {
Xrm.Page.getAttribute("new_price").setValue(card.new_UnitePriceforUCardInhouse.Value);
Xrm.Page.getAttribute("new_price").setSubmitMode("always");
}
}
else if (type == 3) {
if (settlemntType == 2) {
Xrm.Page.getAttribute("new_price").setValue(card.new_UnitePriceforUCardElearning.Value);
Xrm.Page.getAttribute("new_price").setSubmitMode("always");
}
}
}
//计算revenue
function CalculateRevenue() {
var type = Xrm.Page.getAttribute("new_orderitemtype").getValue();
var price = Xrm.Page.getAttribute("new_price").getValue();
var duration = Xrm.Page.getAttribute("new_duration").getValue();
var myModule = Xrm.Page.getAttribute("new_noofmodule").getValue();
var rate = Xrm.Page.getAttribute("new_discountrate").getValue();
var settlement = Xrm.Page.getAttribute("new_settlement").getValue();
var unitPrice = Xrm.Page.getAttribute("new_unitprice").getValue();
var classPrice = Xrm.Page.getAttribute("new_classprice").getValue();
if (type == 1) {
if (rate == null) {
if (settlement == 1 && unitPrice != null) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(duration * unitPrice);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(duration * unitPrice);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
else if (settlement == 1 && unitPrice == null && classPrice != null) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(classPrice);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(classPrice);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
else if (settlement == 2 || settlement == 3) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(duration * price);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(duration * price);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
}
else {
if (settlement == 1 && unitPrice != null) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(duration * unitPrice * rate / 100);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(duration * unitPrice * rate / 100);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
else if (settlement == 1 && unitPrice == null && classPrice != null) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(classPrice * rate / 100);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(classPrice * rate / 100);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
else if (settlement == 2 || settlement == 3) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(duration * price * rate / 100);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(duration * price * rate / 100);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
}
}
else if (type == 2) {
if (rate == null) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(duration * price);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(duration * price);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
else {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(duration * price * rate / 100);
Xrm.Page.getAttribute("new_amountofsettlement").setSubmitMode("always");
Xrm.Page.getAttribute("new_revenue").setValue(duration * price * rate / 100);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
}
else if (type == 3) {
Xrm.Page.getAttribute("new_revenue").setValue(myModule * price);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
//else if (type == 5) {
// Xrm.Page.getAttribute("new_revenue").setValue(duration * price);
// Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
//}
else if (type == 6) {
if (rate == null) {
Xrm.Page.getAttribute("new_revenue").setValue(duration * price);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
else {
Xrm.Page.getAttribute("new_revenue").setValue(duration * price * rate / 100);
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
}
}
//将amount赋值给revenue
function CopyAmount() {
Xrm.Page.getAttribute("new_revenue").setValue(Xrm.Page.getAttribute("new_amountofsettlement").getValue());
Xrm.Page.getAttribute("new_revenue").setSubmitMode("always");
}
//带出学员信息
function TakeStudetInfo() {
var studenRe = Xrm.Page.getAttribute("new_traineename").getValue();
if (studenRe != null) {
var studentEntity = CRK.Retrieve("new_student", studenRe[0].id, new Array("new_Gender", "new_Email", "new_TelOffice", "new_company", "new_Mobile"));
var companyRe = studentEntity.new_company;
if (companyRe != null) {
var copmanyEntity = CRK.Retrieve("Account", companyRe.Id, new Array("PrimaryContactId", "new_Tel", "EMailAddress1"));
}
if (studentEntity.new_Gender) {
Xrm.Page.getAttribute("new_gender1").setValue(1);
}
else {
Xrm.Page.getAttribute("new_gender1").setValue(0);
}
Xrm.Page.getAttribute("emailaddress").setValue(studentEntity.new_Email);
Xrm.Page.getAttribute("new_tel").setValue(studentEntity.new_TelOffice);
Xrm.Page.getAttribute("new_mobile").setValue(studentEntity.new_Mobile);
if (copmanyEntity.PrimaryContactId.Id != null) {
var contactEntity = CRK.Retrieve("Contact", copmanyEntity.PrimaryContactId.Id, new Array("new_TelOffice", "EMailAddress1"));
Xrm.Page.getAttribute("new_contactemail").setValue(contactEntity.EMailAddress1);
Xrm.Page.getAttribute("new_contacttel").setValue(contactEntity.new_TelOffice);
Xrm.Page.getAttribute("new_contacttel").setSubmitMode("always");
Xrm.Page.getAttribute("new_contactemail").setSubmitMode("always");
}
if (studentEntity.new_company.Id != null) {
var comLookup = new Array(1);
comLookup[0] = new Object();
comLookup[0].id = studentEntity.new_company.Id;
comLookup[0].name = studentEntity.new_company.Name;
comLookup[0].entityType = studentEntity.new_company.LogicalName;
Xrm.Page.getAttribute("new_company").setValue(comLookup);
}
if (copmanyEntity.PrimaryContactId.Id != null) {
var conLookup = new Array(1);
conLookup[0] = new Object();
conLookup[0].id = copmanyEntity.PrimaryContactId.Id;
conLookup[0].name = copmanyEntity.PrimaryContactId.Name;
conLookup[0].entityType = copmanyEntity.PrimaryContactId.LogicalName;
Xrm.Page.getAttribute("new_contact").setValue(conLookup);
}
Xrm.Page.getAttribute("new_contacttel").setSubmitMode("always");
Xrm.Page.getAttribute("new_contactemail").setSubmitMode("always");
Xrm.Page.getAttribute("new_contact").setSubmitMode("always");
Xrm.Page.getAttribute("new_company").setSubmitMode("always");
Xrm.Page.getAttribute("new_tel").setSubmitMode("always");
Xrm.Page.getAttribute("emailaddress").setSubmitMode("always");
Xrm.Page.getAttribute("new_gender1").setSubmitMode("always");
}
}
//设置card view
function SetCardView() {
var itemType = Xrm.Page.getAttribute("new_orderitemtype").getValue();
var settlement;
var settlementType;
var companyId;
var company = Xrm.Page.getAttribute("new_company").getValue();
if (company != null) {
companyId = company[0].id;
}
if (itemType == 1) {
settlement = Xrm.Page.getAttribute("new_settlement").getValue();
if (settlement == 2) {
setCradViewFunction(1, 1, companyId);
}
if (settlement == 3) {
setCradViewFunction(1, 2, companyId);
}
}
if (itemType == 2) {
settlemengType = Xrm.Page.getAttribute("new_settlementtype").getValue();
if (settlemengType == 2) {
setCradViewFunction(2, 2, companyId);
}
}
if (itemType == 3) {
settlemengType = Xrm.Page.getAttribute("new_settlementtype").getValue();
if (settlemengType == 2) {
setCradViewFunction(3, 2, companyId);
}
}
}
//set card custom view
var setCradViewFunction = function (type, number, company) {
var filter;
// 指定视图的GUID(任意)
var viewId = "{6FCA2F82-58D0-48f6-B241-2173AF5609FC}";
// 查找实体的逻辑名称
var entityName = "new_discountcard";
// 指定视图的名称
if (number == 1) {
var viewDisplayName = "大客户卡视图";
}
if (number == 2) {
var viewDisplayName = "综合卡视图";
}
if (company != null) {
filter = "<condition attribute='new_company' operator='eq' uitype='account' value='" + company + "' />";
}
// 视图的fetchXml查询
var fetchXml = ["<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>",
"<entity name='new_discountcard'>",
"<attribute name='new_discountcardid' />",
"<attribute name='new_name' />",
"<attribute name='new_company' />",
"<attribute name='new_type' />",
"<order attribute='new_name' descending='false' />",
"<filter type='and'>",
"<condition attribute='new_type' operator='eq' value='" + number + "' />",
"<condition attribute='statecode' operator='eq' value='0'/>",
"<condition attribute='new_status' operator='eq' value='0' />",
filter,
"</filter>",
"</entity>",
"</fetch>", ].join("");
// 指定视图布局XML
var layoutXml = ["<grid name='resultset' object='10013' jump='name' select='1' icon='1' preview='1'>",
"<row name='result' id='new_discountcardid'>",
"<cell name='new_name' width='250'/>",
"<cell name='new_company' width='200'/>",
"</row>",
"</grid>"].join("");
// 是否设置为默认视图
var isDefault = true;
if (type == 1) {
Xrm.Page.getControl("new_card").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
if (type == 2) {
Xrm.Page.getControl("new_card1").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
if (type == 3) {
Xrm.Page.getControl("new_card2").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
}
//设置合同查找视图
//set contract custom view
function SetContractView() {
var value;
var filter;
var number = Xrm.Page.getAttribute("new_orderitemtype").getValue();
var company = Xrm.Page.getAttribute("new_company").getValue();
// 指定视图的GUID(任意)
var viewId = "{6FCA2F82-58D0-48f6-B241-2173AF5609FC}";
// 查找实体的逻辑名称
var entityName = "new_contract";
// 指定视图的名称
if (number == 1) {
var viewDisplayName = "公开课合同关联视图";
value = "<value>1</value>" + "<value>3</value>" + "<value>4</value>" + "<value>9</value>";
//if (number == 2) {
// var viewDisplayName = "内训合同关联视图";
// value = "<value>2</value>" + "<value>4</value>" + "<value>9</value>";
//}
//if (number == 3) {
// var viewDisplayName = "在线合同关联视图";
// value = "<value>4</value>" + "<value>5</value>" + "<value>9</value>";
//}
//if (number == 4) {
// var viewDisplayName = "人才测评合同关联视图";
// value = "<value>6</value>" + "<value>9</value>";
//}
//if (number == 5) {
// var viewDisplayName = "咨询合同关联视图";
// value = "<value>7</value>" + "<value>9</value>";
//}
//if (number == 6) {
// var viewDisplayName = "国际项目合同关联视图";
// value = "<value>9</value>" + "<value>8</value>";
//}
if (company != null) {
filter = "<condition attribute='new_company' operator='eq' uitype='account' value='" + company[0].id + "' />";
}
// 视图的fetchXml查询
var fetchXml = ["<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>",
"<entity name='new_contract'>",
"<attribute name='new_contractid' />",
"<attribute name='new_name' />",
"<attribute name='createdon' />",
"<attribute name='new_company' />",
"<attribute name='new_status' />",
"<attribute name='new_grossamount' />",
"<attribute name='new_contracttype' />",
"<order attribute='new_name' descending='false' />",
"<filter type='and'>",
"<condition attribute='new_contracttype' operator='in'>",
value,
"</condition>",
"<condition attribute='statecode' operator='eq' value='0'/>",
filter,
" </filter>",
"</entity>",
"</fetch>", ].join("");
// 指定视图布局XML
var layoutXml = ["<grid name='resultset' object='10013' jump='name' select='1' icon='1' preview='1'>",
"<row name='result' id='new_contractid'>",
"<cell name='new_name' width='200'/>",
"<cell name='new_company' width='180'/>",
"<cell name='new_contracttype' width='180'/>",
"<cell name='new_grossamount' width='180'/>",
"<cell name='new_status' width='100'/>",
"</row>",
"</grid>"].join("");
// 是否设置为默认视图
var isDefault = true;
// switch (number) {
// case 1:
Xrm.Page.getControl("new_contractno").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
// case 2:
// Xrm.Page.getControl("new_contractno1").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
// case 3:
// Xrm.Page.getControl("new_contractno2").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
//case 4:
// Xrm.Page.getControl("new_contractno3").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
//case 5:
// Xrm.Page.getControl("new_contractno4").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
//case 6:
// Xrm.Page.getControl("new_contractno5").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
// }
Xrm.Page.data.entity.save();
}
}
//自动填写confirm date
var AutoWriteDate = function () {
if (Xrm.Page.getAttribute("new_confirm").getValue()) {
Xrm.Page.getAttribute("new_confirmdate").setValue(new Date(Date()));
Xrm.Page.getAttribute("new_confirmdate").setSubmitMode("always");
}
}
//根据company 自动带出contact,tel,email
var TakeCompanyInfo = function () {
var companyRe = Xrm.Page.getAttribute("new_company").getValue();
var companyEntity = CRK.Retrieve("Account", companyRe[0].id, new Array("PrimaryContactId"));
if (companyEntity.PrimaryContactId.Id != null && companyRe != null) {
var conLookup = new Array(1);
conLookup[0] = new Object();
conLookup[0].id = companyEntity.PrimaryContactId.Id;
conLookup[0].name = companyEntity.PrimaryContactId.Name;
conLookup[0].entityType = companyEntity.PrimaryContactId.LogicalName;
Xrm.Page.getAttribute("new_contact").setValue(conLookup);
var contactEntity = CRK.Retrieve("Contact", companyEntity.PrimaryContactId.Id, new Array("new_TelOffice", "EMailAddress1"));
Xrm.Page.getAttribute("new_contactemail").setValue(contactEntity.EMailAddress1);
Xrm.Page.getAttribute("new_contacttel").setValue(contactEntity.new_TelOffice);
Xrm.Page.getAttribute("new_contacttel").setSubmitMode("always");
Xrm.Page.getAttribute("new_contactemail").setSubmitMode("always");
Xrm.Page.getAttribute("new_contact").setSubmitMode("always");
}
}
function SetOwner()
{
//根据company自动带出company的OwnerId
var orderitemtype = Xrm.Page.getAttribute("new_orderitemtype").getValue();
if (orderitemtype == 1) {
var companyRe = Xrm.Page.getAttribute("new_company").getValue();
if (companyRe[0] != null) {
var companyEntity1 = CRK.Retrieve("Account", companyRe[0].id, new Array("OwnerId"));
if (companyEntity1.OwnerId.LogicalName == 'systemuser' || companyEntity1.OwnerId.LogicalName == 'team') {
var ownerLookup = new Array(1);
ownerLookup[0] = new Object();
ownerLookup[0].id = companyEntity1.OwnerId.Id;
ownerLookup[0].name = companyEntity1.OwnerId.Name;
ownerLookup[0].entityType = companyEntity1.OwnerId.LogicalName;
Xrm.Page.getAttribute("ownerid").setValue(ownerLookup);
}
}
}
}
//给attend date赋值
function SetAttendDate() {
if (Xrm.Page.getAttribute("new_status").getValue() == 4) {
Xrm.Page.getAttribute("new_attenddate").setValue(new Date(Date.now()));
Xrm.Page.getAttribute("new_attenddate").setSubmitMode("always");
}
}
//自动根据合同带出discount rate 以及unit price(散客合同情况下)
function TakeRate() {
if (Xrm.Page.getAttribute("new_contractno").getValue() == null) {
}
else {
var type = Xrm.Page.getAttribute("new_orderitemtype").getValue();
var settlement = Xrm.Page.getAttribute("new_settlement").getValue();
if (type == 1) {
if (settlement == null) {
Xrm.Page.getAttribute("new_contractno").setValue(null);
alert("请先选择结算方式(Settlement)!");
}
else {
var contract = Xrm.Page.getAttribute("new_contractno").getValue();
var oResult = CRK.Retrieve("new_contract", contract[0].id, new Array("new_DiscountRate", "new_ContractType", "new_UnitPrice"));
if (oResult.new_DiscountRate != null) {
Xrm.Page.getAttribute("new_discountrate").setValue(oResult.new_DiscountRate);
Xrm.Page.getAttribute("new_discountrate").setSubmitMode("always");
}
else {
Xrm.Page.getAttribute("new_discountrate").setValue(null);
Xrm.Page.getAttribute("new_discountrate").setSubmitMode("always");
}
if (oResult.new_ContractType != null && oResult.new_ContractType.Value == 1) {
if (oResult.new_UnitPrice != null) {
Xrm.Page.getAttribute("new_unitprice").setValue(oResult.new_UnitPrice.Value);
Xrm.Page.getAttribute("new_unitprice").setSubmitMode("always");
}
}
}
}
else {
var contract = Xrm.Page.getAttribute("new_contractno").getValue();
var oResult = CRK.Retrieve("new_contract", contract[0].id, new Array("new_DiscountRate", "new_ContractType", "new_UnitPrice"));
if (oResult.new_DiscountRate != null) {
Xrm.Page.getAttribute("new_discountrate").setValue(oResult.new_DiscountRate);
Xrm.Page.getAttribute("new_discountrate").setSubmitMode("always");
}
else {
Xrm.Page.getAttribute("new_discountrate").setValue(null);
Xrm.Page.getAttribute("new_discountrate").setSubmitMode("always");
}
if (oResult.new_ContractType != null && oResult.new_ContractType.Value == 1) {
if (oResult.new_UnitPrice != null) {
Xrm.Page.getAttribute("new_unitprice").setValue(oResult.new_UnitPrice.Value);
Xrm.Page.getAttribute("new_unitprice").setSubmitMode("always");
}
}
}
}
}
//开票按钮
function CreateInvoice() {
var nowdate = new Date(Date.now());
var contract = Xrm.Page.getAttribute("new_contractno").getValue();
var amount = Xrm.Page.getAttribute("new_amountofsettlement").getValue();
var company = Xrm.Page.getAttribute("new_company").getValue();
var itemId = Xrm.Page.data.entity.getId();
var companyInfo = CRK.Retrieve("Account", company[0].id, new Array("Name", "new_BankName", "new_BankAccount", "new_TaxID", "new_Address"));
//var parameters = {};
//parameters["new_totalamount"] = amount;
//parameters["new_contractno"] = contract[0].id;
//parameters["new_contractnoname"] = contract[0].name;
//parameters["new_company"] = company[0].id;
//parameters["new_companyname"] = company[0].name;
//// parameters["new_invoicename"] = companyInfo.Name;
//parameters["new_taxid"] = companyInfo.new_TaxID == null ? null : companyInfo.new_TaxID;
//parameters["new_bankname"] = companyInfo.new_BankName == null ? null : companyInfo.new_BankName;
//parameters["new_bankaccount"] = companyInfo.new_BankAccount == null ? null : companyInfo.new_BankAccount;
//parameters["new_address"] = companyInfo.new_Address == null ? null : companyInfo.new_Address;
//// parameters["new_invoicedate"] = new Date(Date.now()).format("MM/dd/yyyy");
//parameters["new_itemguid"] = itemId;
//Xrm.Utility.openEntityForm("new_salesinvoice", null, parameters);
var extraqs = "new_totalamount=" + amount;
extraqs += "&new_contractno=" + contract[0].id;
extraqs += "&new_contractnoname=" + contract[0].name
extraqs += "&new_company=" + company[0].id;
extraqs += "&new_companyname=" + company[0].name;
extraqs += "&new_taxid=" + companyInfo.new_TaxID == null ? null : companyInfo.new_TaxID;
extraqs += "&new_bankname=" + companyInfo.new_BankName == null ? null : companyInfo.new_BankName;
extraqs += "&new_bankaccount=" + companyInfo.new_BankAccount == null ? null : companyInfo.new_BankAccount;
extraqs += "&new_address=" + companyInfo.new_Address == null ? null : companyInfo.new_Address;
extraqs += "&new_itemguid=" + itemId;
var features = "location=no,menubar=no,status=no,toolbar=no";
window.open("/main.aspx?etn=new_salesinvoice&pagetype=entityrecord&extraqs=" +
encodeURIComponent(extraqs), "_blank", features, false);
}
//开票按钮的显隐性
function IsVisibleInvoiveBtn() {
var formType = Xrm.Page.ui.getFormType()
if (formType == 2) {
var oType = Xrm.Page.getAttribute("new_orderitemtype").getValue();
var settlement = Xrm.Page.getAttribute("new_settlement").getValue();
if (oType == 1 && settlement == 1) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
//save
function OnSave() {
Xrm.Page.data.entity.save();
}
//公开课时根据settlement控制合同的是必填
function SetContractLevel() {
var oType = Xrm.Page.getAttribute("new_orderitemtype").getValue();
var settlement = Xrm.Page.getAttribute("new_settlement").getValue();
if (oType == 1 && (settlement == 2 || settlement == 4 || settlement == 5)) {
Xrm.Page.getAttribute("new_contractno").setRequiredLevel("none");
}
else {
Xrm.Page.getAttribute("new_contractno").setRequiredLevel("required");
}
}
//根据联系人带出电话和邮箱
function TakeContactInfo() {
var contact = Xrm.Page.getAttribute("new_contact").getValue();
if (contact != null) {
var contactEntity = CRK.Retrieve("Contact", contact[0].id, new Array("new_TelOffice", "EMailAddress1"));
Xrm.Page.getAttribute("new_contactemail").setValue(contactEntity.EMailAddress1);
Xrm.Page.getAttribute("new_contacttel").setValue(contactEntity.new_TelOffice);
Xrm.Page.getAttribute("new_contacttel").setSubmitMode("always");
Xrm.Page.getAttribute("new_contactemail").setSubmitMode("always");
}
}
//oc colne orderitem
function Colne() {
var itemtype = Xrm.Page.getAttribute("new_orderitemtype").getValue();
if (itemtype != null && itemtype == 1) {
var trainee = Xrm.Page.getAttribute("new_traineename").getValue();
var gender = Xrm.Page.getAttribute("new_gender1").getValue();
var mobile = Xrm.Page.getAttribute("new_mobile").getValue();
var tel = Xrm.Page.getAttribute("new_tel").getValue();
var email = Xrm.Page.getAttribute("emailaddress").getValue();
var company = Xrm.Page.getAttribute("new_company").getValue();
var contact = Xrm.Page.getAttribute("new_contact").getValue();
var contatcmail = Xrm.Page.getAttribute("new_contactemail").getValue();
var contacttel = Xrm.Page.getAttribute("new_contacttel").getValue();
var product = Xrm.Page.getAttribute("new_product").getValue();
var classdate = Xrm.Page.getAttribute("new_classdate").getValue();
var status = Xrm.Page.getAttribute("new_status").getValue();
var callstatus = Xrm.Page.getAttribute("new_callbackstatus").getValue();
var cancelreason = Xrm.Page.getAttribute("new_cancelreason").getValue();
var followuptime = Xrm.Page.getAttribute("new_followuptime").getValue();
var confirm = Xrm.Page.getAttribute("new_confirm").getValue();
//var attenddate = Xrm.Page.getAttribute("new_attenddate").getValue();
var questionnaire = Xrm.Page.getAttribute("new_questionnaire").getValue();
var feedback = Xrm.Page.getAttribute("new_feedbackcall").getValue();
var contract = Xrm.Page.getAttribute("new_contractno").getValue();
var notification = Xrm.Page.getAttribute("new_notification").getValue();
var source = Xrm.Page.getAttribute("new_source").getValue();
var distribute = Xrm.Page.getAttribute("new_distributor").getValue();
var discountrate = Xrm.Page.getAttribute("new_discountrate").getValue();
var classprice = Xrm.Page.getAttribute("new_classprice").getValue();
var unitprice = Xrm.Page.getAttribute("new_unitprice").getValue();
var memo = Xrm.Page.getAttribute("new_remark").getValue();
var settlement = Xrm.Page.getAttribute("new_settlement").getValue();
var duration = Xrm.Page.getAttribute("new_duration").getValue();
var card = Xrm.Page.getAttribute("new_card").getValue();
var settlementcard = Xrm.Page.getAttribute("new_settlementofcard").getValue();
var price = Xrm.Page.getAttribute("new_price").getValue();
var avaliable = Xrm.Page.getAttribute("new_availablepd").getValue();
var freeavaliable = Xrm.Page.getAttribute("new_availablefreepd").getValue();
//var statussettlement = Xrm.Page.getAttribute("new_statusofsettlement").getValue();
//var billstatus = Xrm.Page.getAttribute("new_billedstatus").getValue();
//var collectionstatus = Xrm.Page.getAttribute("new_collectionstatus").getValue();
var collectiondate = Xrm.Page.getAttribute("new_collectiondate").getValue();
var amountofsettlement = Xrm.Page.getAttribute("new_amountofsettlement").getValue();
var revenue = Xrm.Page.getAttribute("new_revenue").getValue();
var queryCompanyOwner = CRK.Retrieve("Account", Xrm.Page.getAttribute("new_company").getValue()[0].id, ["OwnerId"]);
var parameters = {};
if (queryCompanyOwner != null) {
parameters["ownerid"] = queryCompanyOwner.OwnerId.Id;
parameters["owneridname"] = queryCompanyOwner.OwnerId.Name;
parameters["owneridtype"] = queryCompanyOwner.OwnerId.LogicalName;
}
if (trainee != null) {
parameters["new_traineename"] = trainee[0].id;
parameters["new_traineenamename"] = trainee[0].name;
}
if (gender != null) {
parameters["new_gender1"] = gender;
}
if (mobile != null) {
parameters["new_mobile"] = mobile;
}
if (tel != null) {
parameters["new_tel"] = tel;
}
if (email != null) {
parameters["emailaddress"] = email;
}
if (company != null) {
parameters["new_company"] = company[0].id;
parameters["new_companyname"] = company[0].name;
}
if (contact != null) {
parameters["new_contact"] = contact[0].id;
parameters["new_contactname"] = contact[0].name;
}
if (contatcmail != null) {
parameters["new_contactemail"] = contatcmail;
}
if (contacttel != null) {
parameters["new_contacttel"] = contacttel;
}
// ---------------------------------------------------------------------------
if (status != null) {
parameters["new_status"] = 0; //status;
}
//if (callstatus != null) {
// parameters["new_callbackstatus"] = callstatus;
//}
//if (cancelreason != null) {
// parameters["new_cancelreason"] = cancelreason;
//}
if (followuptime != null) {
parameters["new_followuptime"] = followuptime.format("MM/dd/yyyy");
}
if (confirm != null) {
parameters["new_confirm"] = confirm;
}
//if (status != null && status == 4) {
// parameters["new_attenddate"] = attenddate.format("MM/dd/yyyy");
//}
if (questionnaire != null) {
parameters["new_questionnaire"] = questionnaire;
}
if (feedback != null) {
parameters["new_feedbackcall"] = feedback;
}
//--------------------------------------------------------------------
if (contract != null) {
parameters["new_contractno"] = contract[0].id;
parameters["new_contractnoname"] = contract[0].name;
}
if (notification != null) {
parameters["new_notification"] = notification;
}
if (source != null) {
parameters["new_source"] = 3;
}
if (distribute != null) {
parameters["new_distributor"] = distribute[0].id;
parameters["new_distributorname"] = distribute[0].name;
}
if (discountrate != null) {
parameters["new_discountrate"] = discountrate;
}
if (classprice != null) {
parameters["new_classprice"] = classprice;
}
if (unitprice != null) {
parameters["new_unitprice"] = unitprice;
}
if (memo != null) {
parameters["new_remark"] = memo;
}
//-------------------------------------------------------------------------
if (settlement != null) {
parameters["new_settlement"] = settlement;
}
if (duration != null) {
parameters["new_duration"] = duration;
}
if (card != null) {
parameters["new_card"] = card[0].id;
parameters["new_cardname"] = card[0].name;
}
if (settlementcard != null) {
parameters["new_settlementofcard"] = settlementcard;
}
if (price != null) {
parameters["new_price"] = price;
}
if (avaliable != null) {
parameters["new_availablepd"] = avaliable;
}
if (freeavaliable != null) {
parameters["new_availablefreepd"] = freeavaliable;
}
if (itemtype != null) {
parameters["new_orderitemtype"] = itemtype;
}
//--11111111111111111111111111111111111111111111111111111111111111111111111
//if (statussettlement != null) {
// parameters["new_statusofsettlement"] = statussettlement;
//}
//if (billstatus != null) {
// parameters["new_billedstatus"] = billstatus;
//}
//if (collectionstatus != null) {
// parameters["new_collectionstatus"] = collectionstatus;
//}
if (collectiondate != null) {
parameters["new_collectiondate"] = collectiondate.format("MM/dd/yyyy");
}
if (amountofsettlement != null) {
parameters["new_amountofsettlement"] = amountofsettlement;
}
if (revenue != null) {
parameters["new_revenue"] = revenue;
}
if (product != null) {
parameters["new_product"] = product[0].id;
parameters["new_productname"] = product[0].name;
}
if (classdate != null) {
parameters["new_classdate"] = classdate.format("MM/dd/yyyy");
}
Xrm.Utility.openEntityForm("new_oderitem", null, parameters);
}
else if (itemtype != null && itemtype == 2) {
var contact = Xrm.Page.getAttribute("new_contact").getValue();
var company = Xrm.Page.getAttribute("new_company").getValue();
var contract = Xrm.Page.getAttribute("new_contractno").getValue();
var contatcmail = Xrm.Page.getAttribute("new_contactemail").getValue();
var contacttel = Xrm.Page.getAttribute("new_contacttel").getValue();
var remark = Xrm.Page.getAttribute("new_remark").getValue();
var lable = Xrm.Page.getAttribute("new_labelandcert").getValue();
var feedback = Xrm.Page.getAttribute("new_feedbackcall").getValue();
var confirm = Xrm.Page.getAttribute("new_confirm").getValue();
var confirmdate = Xrm.Page.getAttribute("new_confirmdate").getValue();
var billstatus = Xrm.Page.getAttribute("new_billedstatus").getValue();
var collectionstatus = Xrm.Page.getAttribute("new_collectionstatus").getValue();
var collectiondate = Xrm.Page.getAttribute("new_collectiondate").getValue();
var product = Xrm.Page.getAttribute("new_product").getValue();
var classdate = Xrm.Page.getAttribute("new_classdate").getValue();
var duration = Xrm.Page.getAttribute("new_duration").getValue();
var amount = Xrm.Page.getAttribute("new_amountofsettlement").getValue();
var revenue = Xrm.Page.getAttribute("new_revenue").getValue();
var settlement = Xrm.Page.getAttribute("new_settlementtype").getValue();
var card = Xrm.Page.getAttribute("new_card").getValue();
var price = Xrm.Page.getAttribute("new_price").getValue();
var discount = Xrm.Page.getAttribute("new_discountrate").getValue();
var memo = Xrm.Page.getAttribute("new_remark").getValue();
var parameters = {};
if (contact != null) {
parameters["new_contact"] = contact[0].id;
parameters["new_contactname"] = contact[0].name;
}
if (company != null) {
parameters["new_company"] = company[0].id;
parameters["new_companyname"] = company[0].name;
}
if (contract != null) {
parameters["new_contractno"] = contract[0].id;
parameters["new_contractnoname"] = contract[0].name;
}
if (contatcmail != null) {
parameters["new_contactemail"] = contatcmail;
}
if (contacttel != null) {
parameters["new_contacttel"] = contacttel;
}
if (discount != null) {
parameters["new_discountrate"] = discount;
}
if (remark != null) {
parameters["new_remark"] = remark;
}
if (lable != null) {
parameters["new_labelandcert"] = lable;
}
if (feedback != null) {
parameters["new_feedbackcall"] = feedback;
}
if (confirm != null) {
parameters["new_confirm"] = confirm;
}
if (confirmdate != null) {
parameters["new_confirmdate"] = confirmdate.format("MM/dd/yyyy");
}
if (billstatus != null) {
parameters["new_billedstatus"] = billstatus;
}
if (collectionstatus != null) {
parameters["new_collectionstatus"] = collectionstatus;
}
if (collectiondate != null) {
parameters["new_collectiondate"] = collectiondate.format("MM/dd/yyyy");
}
if (product != null) {
parameters["new_product"] = product[0].id;
parameters["new_productname"] = product[0].name;
}
if (classdate != null) {
parameters["new_classdate"] = classdate.format("MM/dd/yyyy");
}
if (duration != null) {
parameters["new_duration"] = duration;
}
if (amount != null) {
parameters["new_amountofsettlement"] = amount;
}
if (revenue != null) {
parameters["new_revenue"] = revenue;
}
if (settlement != null) {
parameters["new_settlementtype"] = settlement;
}
if (card != null) {
parameters["new_card"] = card[0].id;
parameters["new_cardname"] = card[0].name;
}
if (price != null) {
parameters["new_price"] = price;
}
if (itemtype != null) {
parameters["new_orderitemtype"] = itemtype;
}
if (memo != null) {
parameters["new_remark"] = memo;
}
Xrm.Utility.openEntityForm("new_oderitem", null, parameters);
}
}
//根据订单编号带出产品,日期和duration
function TakeInfoFromOrder() {
var order = Xrm.Page.getAttribute("new_orderno").getValue();
var orderType = Xrm.Page.getAttribute("new_orderitemtype").getValue();
Xrm.Page.getAttribute("new_duration").setValue(null);
Xrm.Page.getAttribute("new_classdate").setValue(null);
Xrm.Page.getAttribute("new_product").setValue(null);
Xrm.Page.getAttribute("new_classprice").setValue(null);
if (orderType != null && (orderType == 1 || orderType == 2) && order != null) {
var orderEntity = CRK.Retrieve("new_order", order[0].id, new Array("new_Product", "new_Field1", "new_Duration", "new_City", "new_Trainer", "new_Date", "new_Price"));
if (orderEntity != null && orderEntity.new_Product.Id != null) {
var productLookup = new Array(1);
productLookup[0] = new Object();
productLookup[0].id = orderEntity.new_Product.Id;
productLookup[0].name = orderEntity.new_Product.Name;
productLookup[0].entityType = orderEntity.new_Product.LogicalName;
Xrm.Page.getAttribute("new_product").setValue(productLookup);
}
if (orderEntity != null && orderEntity.new_Date != null) {
Xrm.Page.getAttribute("new_classdate").setValue(new Date(new Date(parseInt(orderEntity.new_Date.substring(6, 19))).getTime()));
}
if (orderEntity != null && orderEntity.new_Duration != null) {
Xrm.Page.getAttribute("new_duration").setValue(orderEntity.new_Duration);
}
Xrm.Page.getAttribute("new_classprice").setValue(orderEntity.new_Price.Value);
}
// OnSave();
}
//从Evaluation实体带出Overall Evaluation
function getEvaluation() {
//订单明细类型为公开课
debugger;
if (Xrm.Page.getAttribute("new_orderitemtype").getValue() == 1) {
if (Xrm.Page.getAttribute("new_orderno").getValue() != null && Xrm.Page.getAttribute("new_traineename").getValue() != null) {
var orderId = Xrm.Page.getAttribute("new_orderno").getValue()[0].id; //订单明细上的订单编号
var traineeNameId = Xrm.Page.getAttribute("new_traineename").getValue()[0].id; //订单明细上的学员名称
var filterstr = "new_TraineeName/Id eq guid'" + traineeNameId + "' and new_OrderNo/Id eq guid'" + orderId + "'";
var result = CRK.RetrieveMultiple("new_questionnaire", new Array("new_OverallEvaluation"), filterstr).results.length;
if (result == 1) { //表示搜索到一条问卷
var overallEvaluation = CRK.RetrieveMultiple("new_questionnaire", new Array("new_OverallEvaluation"), filterstr).results[0].new_OverallEvaluation.Value; //获取问卷上的new_overallevaluation
Xrm.Page.getAttribute("new_evaluation").setValue(overallEvaluation + "");
}
}
}
}
//若是免费报名,则设置amount 为0
function setAmountZero() {
if (Xrm.Page.getAttribute("new_settlement").getValue() == 4 || Xrm.Page.getAttribute("new_settlement").getValue() == 5 || (Xrm.Page.getAttribute("new_settlement").getValue() == 2 && Xrm.Page.getAttribute("new_settlementofcard").getValue() == 2)) {
Xrm.Page.getAttribute("new_amountofsettlement").setValue(0);
Xrm.Page.getAttribute("new_revenue").setValue(0)
}
}
//根据订单明细状态更改订单字段的查询条件
function SetOrderFilterByType() {
var value;
var number = Xrm.Page.getAttribute("new_orderitemtype").getValue();
// 指定视图的GUID(任意)
var viewId = "{6FCA2F82-58D0-48f6-B241-2173AF5609FC}";
// 查找实体的逻辑名称
var entityName = "new_order";
var viewDisplayName;
// 指定视图的名称
if (number == 1) {
viewDisplayName = "公开课订单视图";
value = "<condition attribute='new_ordertype' operator='eq' value='1' />";
}
if (number == 2) {
viewDisplayName = "内训订单视图";
value = "<condition attribute='new_ordertype' operator='eq' value='2' />";
}
if (number == 3) {
viewDisplayName = "在线学习订单视图";
value = "<condition attribute='new_ordertype' operator='eq' value='3' />";
}
if (number == 4) {
viewDisplayName = "人才测评订单视图";
value = "<condition attribute='new_ordertype' operator='eq' value='4' />";
}
if (number == 5) {
viewDisplayName = "咨询订单视图";
value = "<condition attribute='new_ordertype' operator='eq' value='5' />";
}
if (number == 6) {
viewDisplayName = "国际项目订单视图";
value = "<condition attribute='new_ordertype' operator='eq' value='6' />";
}
// 视图的fetchXml查询
var fetchXml = ["<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>",
"<entity name='new_order'>",
"<attribute name='new_name' />",
"<attribute name='new_product' />",
"<attribute name='new_date' />",
"<attribute name='new_ordertype' />",
"<attribute name='new_orderid' />",
"<order attribute='new_product' descending='true' />",
"<filter type='and'>",
value,
"<condition attribute='statecode' operator='eq' value='0' />",
"</filter>",
"</entity>",
"</fetch>", ].join("");
// 指定视图布局XML
var layoutXml = ["<grid name='resultset' object='10013' jump='name' select='1' icon='1' preview='1'>",
"<row name='result' id='new_orderid'>",
"<cell name='new_name' width='200'/>",
"<cell name='new_product' width='180'/>",
"<cell name='new_date' width='180'/>",
"<cell name='new_ordertype' width='180'/>",
"</row>",
"</grid>"].join("");
// 是否设置为默认视图
var isDefault = true;
if (number == 1) {
Xrm.Page.getControl("new_orderno").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
if (number == 2) {
Xrm.Page.getControl("new_orderno1").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
if (number == 3) {
Xrm.Page.getControl("new_orderno2").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
if (number == 4) {
Xrm.Page.getControl("new_orderno3").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
if (number == 5) {
Xrm.Page.getControl("new_orderno4").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
if (number == 6) {
Xrm.Page.getControl("new_orderno5").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}
Xrm.Page.data.entity.save();
}
//根据form state 锁定订单号字段
function LockOrderField() {
var formType = Xrm.Page.ui.getFormType();
if (formType != 1) {
Xrm.Page.getControl("new_orderno").setDisabled("true");
Xrm.Page.getControl("new_orderno1").setDisabled("true");
Xrm.Page.getControl("new_orderno2").setDisabled("true");
Xrm.Page.getControl("new_orderno3").setDisabled("true");
Xrm.Page.getControl("new_orderno4").setDisabled("true");
Xrm.Page.getControl("new_orderno5").setDisabled("true");
}
}
console