码迷,mamicode.com
首页 > Web开发 > 详细

Microsoft Dynamics CRM 2013 Js Odata 查询

时间:2015-02-13 13:08:44      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

实现功能:
   在新建记录时,(大区,省区,城市)的值默认为当前用户的值。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

 

Microsoft Dynamics CRM 2013 Js Odata 查询

标签:

原文地址:http://www.cnblogs.com/guozh-bk/p/4289974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!