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); } }); } }
昨日龌龊不足夸,今日放荡思无涯。
--华芯