dynamics365 省市级联

 1.城市:new_city

2.省份:new_province

function onload(){//绑定窗体的加载事件
    var FromType = Xrm.Page.ui.getFormType();
    if(FromType==1){//FromType=1是表示在创建的时候
        cityLookup();
    }else if (FromType == 2){//FromType=2是表示在查看详情的时候
        cityLookup();
    } 
}

function cityLookup() {//绑定到城市的onchange 事件
    Xrm.Page.getControl("new_city").addPreSearch(function () {
        addprovince();
    })
}
function addprovince() {
    debugger;
    var gl = Xrm.Page.getAttribute("new_province").getValue(); //省份取值
    var fetchXml = "";
    var a=null;
    if (gl != null || gl != "") {//判断省份的值是否为空
        //把省份的值带入Featchxml语句查询
        fetchXml = "<filter type='and'><condition attribute='new_province' operator='eq' value='" + gl[0].id + "'/></filter>";
    }
    else {
        //将城市的值变成空
        fetchXml = "<filter type='and'><condition attribute='new_province' operator='null' /></filter>";
        Xrm.Page.getControl("new_city").setValue(a);
    }
    Xrm.Page.getControl("new_city").addCustomFilter(fetchXml); //为城市赋值

}
//省份province无数据,则城市也变成空
function addprovinceNUll(){//绑定到省份的onchange 事件
    debugger;
    var province = Xrm.Page.getAttribute("new_province").getValue(); //省份取值
    var provincenull=null;
    if(province==null||province==""){//判断省份是否为空
        Xrm.Page.getAttribute("new_city").setValue(provincenull); //为城市赋值
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值