• 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
  • 相关阅读:
    【算法笔记】B1015 德才论
    【算法笔记】B1014 福尔摩斯的约会
    【算法笔记】B1013 数素数
    【算法笔记】B1012 数字分类
    【算法笔记】B1011 A+B 和 C
    【算法笔记】B1010 一元多项式求导
    【算法笔记】B1009 说反话
    【算法笔记】B1008 数组元素循环右移问题
    SSLOJ 1336.膜拜神牛
    SSLOJ 1335.蛋糕切割
  • 原文地址:https://www.cnblogs.com/guozh-bk/p/4289974.html
Copyright © 2020-2023  润新知