Microsoft Dynamics CRM 2013 Js Odata 查询

实现功能:
   在新建记录时,(大区,省区,城市)的值默认为当前用户的值。tips:字段均为lookup类型;
 

技术分享
function Default_region(){

var fromtype=Xrm.Page.ui.getFormType();

if(fromtype==1){

var userids=Xrm.Page.context.getUserId();

var url=Xrm.Page.context.getClientUrl();

var Odata=url+"/XRMServices/2011/OrganizationData.svc/";

var database="SystemUserSet";

var fidt="?$filter=SystemUserId eq (guid‘" + userids+ "‘)";

var queryurl=Odata+database+fidt;

 $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: queryurl,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data) {
                //大区
                var region= data.d.results[0].new_region;
                var lookupregion= [];
                lookupregion[0] = {};
                lookupregion[0].id = "{"+region.Id+"}";
                lookupregion[0].entityType =region.LogicalName;
                lookupregion[0].name = region.Name;
                Xrm.Page.getAttribute(‘new_region‘).setValue(lookupregion);

               //省区
              var state =data.d.results[0].new_province;
              var lookupstate =[];
              lookupstate[0] = {};
              lookupstate[0].id = "{"+state.Id+"}";
              lookupstate[0].entityType =state.LogicalName;
              lookupstate[0].name = state.Name;
              Xrm.Page.getAttribute(‘new_state‘).setValue(lookupstate);

               //城市
              var city=data.d.results[0].new_city;
              var lookupcity =[];
              lookupcity[0] = {};
              lookupcity[0].id = "{"+city.Id+"}";
              lookupcity[0].entityType =city.LogicalName;
              lookupcity[0].name = city.Name;
              Xrm.Page.getAttribute(‘new_city‘).setValue(lookupcity);

            }
        });
}
}
View Code

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。