Example 2: Win Type & customized button

Example 2: Win Type & customized button

  • 1: Window OnLoad:
    window type: create, edit, readonly
    form type: editable / disable all
  • 2: Window OnSave:
    Field Mandatory submit
  • 3: Field OnChange:
    set the value of the field including drop down list
    Retrieve Account info
  • 4: btn_Submit :
    Apply for submit
    Update Account info
function form_OnLoad(){
	var formType=Xrm.Page.ui.getFormType();
	if (formType==1) {
		Xrm.Page.getAttribute("new_applydate").setValue(new Date());
	} else if (formType==2) {
		Xrm.Page.getControl("new_name").setDisabled(true);
	}
	var formStatus=Xrm.Page.getAttribute("new_formstatus").getValue();
	if (formStatus==2) {
		form_disabledAll();
	}
}			
function form_disableAll(){
///disable all object on form
var controls = Xrm.Page.ui.controls.get();    
for (var i in controls) {
        var control = controls[i];        
        if (control.getControlType() != "iframe" && control.getControlType() != "webresource"  && control.getControlType() != "subgrid" && control.getDisabled() == false) {            
        	control.setDisabled(true);        
        }  
 	 }
}
function form_OnSave(){
//mandatory submitt
	Xrm.Page.getAttribute("new_creditcode").setSubmitMode("always");
}
function new_account_id_OnChange(){
//customer name
var new_accountVal=Xrm.Page.getAttribute("new_account_id".getValue();
if (new_accountVal!=null&&new_accountVal[0]!=null) {
    var obj=getAccountInfo(new_accountVal[0].id);
    if (obj!=null) {
    Xrm.Page.getAttribute("new_creditcode").setValue(obj.new_creditcode);
    Xrm.Page.getAttribute("new_mobilephone").setValue(obj.new_mobilephone);
    Xrm.Page.getAttribute("new_address").setValue(obj.new_address);
    //country
    Xrm.Page.getAttribute("new_country_id").setValue([{"id":obj["_new_country_id_value"], "name":obj["_new_country_id_value@OData.Community.Display.V1.FormattedValue"],"entitytype":"new_country"}])
	Xrm.Page.getAttribute("new_province_id").setValue([{"id":obj["_new_province_id_value"],"name":obj["_new_province_id_value@OData.Community.Display.V1.FormattedValue"],"entitytype":"new_province"}])
	Xrm.Page.getAttribute("new_city_id").setValue([{"id":obj["_new_city_id_value"],"name":obj["_new_city_id_value@OData.Community.Display.V1.FormattedValue"],"entitytype":"new_city"}])    
    } //obj!=null
    else{
    Xrm.Page.getAttribute("new_creditcode").setValue(null);
    Xrm.Page.getAttribute("new_mobilephone").setValue(null);
    Xrm.Page.getAttribute("new_address").setValue(null);
    Xrm.Page.getAttribute("new_country_id").setValue(null);
    Xrm.Page.getAttribute("new_province_id").setValue(null);
    Xrm.Page.getAttribute("new_city_id").setValue(null);
    } //obj=null
}
}
function getAccountInfo(id){
id=id.replace("{","").replace("}","");
var webUrl=Xrm.Page.context.getClientUrl()+"/api/data/v9.0/";
var req=new XMLHttpRequest();
req.open("GET",encodeURI(webUrl+"accounts("+id+")?$select=name,new_creditcode,_new_country_id_value,_new_province_id_value,_new_city_id_value,new_mobilephone,new_address"),true)
req.setRequestHeader("Accept","application/json");
req.setRequestHeader("Content-Type","application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion","4.0");
req.setRequestHeader("OData-Version","4.0");
req.setRequestHeader("Prefer","odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.send();
if (req.status==200)
	return JSON.parse(req.responseText);
else
	throw new Error(JSON.parse(this.responseText).error.message);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值