Implementation features:
When you create a new record, the value of (region, province, city) defaults to the value of the current user. Tips: Fields are the lookup type;
functiondefault_region () {varFromtype=Xrm.Page.ui.getFormType ();if(fromtype==1){varuserids=Xrm.Page.context.getUserId ();varUrl=Xrm.Page.context.getClientUrl ();varodata=url+ "/xrmservices/2011/organizationdata.svc/";varDatabase= "Systemuserset";varFidt= "? $filter =systemuserid eq (GUID '" + userids+ "')";varQueryurl=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) {//Large Area varregion= data.d.results[0].new_region; varlookupregion= []; lookupregion[0] = {}; lookupregion[0].id = "{" +region. Id+ "}"; lookupregion[0].entitytype =Region . LogicalName; lookupregion[0].name =Region . Name; Xrm.Page.getAttribute (' New_region '). SetValue (lookupregion); //Provinces varState =data.d.results[0].new_province; varLookupstate =[]; lookupstate[0] = {}; lookupstate[0].id = "{" +state. Id+ "}"; lookupstate[0].entitytype =State . LogicalName; lookupstate[0].name =State . Name; Xrm.Page.getAttribute (' New_state '). SetValue (Lookupstate); //City varCity=data.d.results[0].new_city; varLookupcity =[]; 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
Microsoft Dynamics CRM-Js Odata Query