Dynamics CRM2016 Web API之通过实体的primary key查询记录
2016-03-14 22:11
399 查看
CRM2016启用了webapi 而弃用了odata,作为码农的我们又开始学习新东西了。
下面是一段简单的查询代码,通过systemuser的primary key来查询一条记录
Web API查询方式
这里我查询的是全部字段,如果是要查询指定字段写法参考sdk
odata的查询方式
通过上述两种方式的代码中可以看到些许的差别,主要是在url和返回json数据的处理上,当然这只是最简单的R,还有复杂的R还有CUD需要慢慢去探索。
下面是一段简单的查询代码,通过systemuser的primary key来查询一条记录
Web API查询方式
var userId = Xrm.Page.getAttribute("ownerid").getValue()[0].id; var appellation; $.ajax({ async: false, type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: Xrm.Page.context.getClientUrl() + "/api/data/v8.0/systemusers(" + userId.replace('{', '').replace('}', '') + ")", success: function (data, textStatus, XmlHttpRequest) { appellation = data.lastname + data.firstname + '-' + data.salutation; }, error: function (XmlHttpRequest, textStatus, errorThrown) { } });
这里我查询的是全部字段,如果是要查询指定字段写法参考sdk
odata的查询方式
var userId = Xrm.Page.getAttribute("ownerid").getValue()[0].id; var appellation; $.ajax({ async: false, type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/SystemUserSet(guid'" + userId + "')", success: function (data, textStatus, XmlHttpRequest) { appellation = data.d.lastname + data.d.firstname + '-' + data.d.salutation; }, error: function (XmlHttpRequest, textStatus, errorThrown) { } }); }
通过上述两种方式的代码中可以看到些许的差别,主要是在url和返回json数据的处理上,当然这只是最简单的R,还有复杂的R还有CUD需要慢慢去探索。
相关文章推荐
- AlphaGo比Windows和Apple有更远更持久的影响力
- 手动绑定数据到GridView并实现编辑,删除,取消···
- Android 控件的触摸事件传递与处理
- visual c++ 中的stdafx.h头文件的作用
- HDU 5291 Candy Distribution DP 差分 前缀和优化
- Longest Substring Without Repeating Characters
- MySQL的高级查询
- Longest Substring Without Repeating Characters
- 解决使用tomcat6-maven-plugin时的"can not invoke tomcat manager"问题
- maven+eclipse基础
- C++ 多线程并发控制——互斥锁 pthread_mutex
- 二分查找算法----递归&&非递归
- 软件工程作业 四则运算(二)
- 第一堂第一次
- 使用axis调用webservice
- matlab和C++混编(1)配置开发环境
- Problem F: 结构体--学生信息排序
- 安卓开发常见问题
- 巧妙利用单调队列(12哈工程多校)(3530)
- Fiddler