Dynamic CRM 2016使用WEB API创建查询记录(js)
2017-10-09 14:52
375 查看
1.使用Post创建实体记录
代码如下
创建成功,创建结果如图:
返回响应内容如下:
2.使用Get查询实体记录
代码如下:
function RetrieveUsingWebAPI() {
var req = new XMLHttpRequest();
req.open("GET", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts?$select=name&$top=2"), true);//查询account实体两条数据
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
var data = JSON.parse(this.response).value;
}
else {
var error = JSON.parse(this.response).error;
}
}
};
req.send();
}查询信息如下图:
代码如下
function CreateUsingWebAPI() { var req = new XMLHttpreq() var str = null; debugger; req.open("POST", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts"), true); req.setreqHeader("Accept", "application/json"); req.setreqHeader("Content-Type", "application/json; CHARSET=utf-8"); req.setreqHeader("OData-MaxVersion", "4.0");//可以省略此行 req.setreqHeader("OData-Version", "4.0");//可以省略此行 req.send(JSON.stringify({ name: "Sample account",//文本类型 new_twooptions: true,//bool类型 new_money1: 1000,//货币类型 new_optionset: 1000,//选项集 new_date: new Date(),//日期 "new_lookup@odata.bind": "/accounts(D5957650-59A5-E711-80C5-AFF8F414EE97)"//查找类型 })); req.onreadystatechange = function () { if (this.readyState == 4) { if (this.status == 204) { var accountUri = req.getResponseHeader("OData-EntityId"); alert("Created account with URI: " + accountUri); } else { var error = JSON.parse(req.response).error; alert(error.message); } } }; }
创建成功,创建结果如图:
返回响应内容如下:
HTTP/1.1 204 No Content OData-Version: 4.0 OData-EntityId: cc_WebAPI_ServiceURI/accounts(7eb682f1-ca75-e511-80d4-00155d2a68d1)alert对应结果为:
2.使用Get查询实体记录
代码如下:
function RetrieveUsingWebAPI() {
var req = new XMLHttpRequest();
req.open("GET", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts?$select=name&$top=2"), true);//查询account实体两条数据
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
var data = JSON.parse(this.response).value;
}
else {
var error = JSON.parse(this.response).error;
}
}
};
req.send();
}查询信息如下图:
相关文章推荐
- Dynamic CRM 2016使用WEB API 模拟用户查询记录(js)
- Dynamic CRM 2016使用WEB API FetchXml查询特定记录(js)
- Dynamic CRM 2016使用WEB API删除记录(js)
- Dynamic CRM 2016使用WEB API更新记录(js)
- MOSS Search学习记录(十):MOSS Visual How To使用SharePoint Server 2007搜索对象模型编程创建搜索查询
- mysql使用rand随机查询记录效率测试
- mysql使用rand随机查询记录效率测试
- js使用对象直接量创建对象的代码
- 使用distinct在查询多条不重复记录值的解决办法(转)
- js使用对象直接量创建对象的代码
- [原创]ACCESS中使用SQL语句查询另一表中不存在的记录
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- SQL灵活使用:分组查询各组的详细记录
- mysql使用rand随机查询记录效率测试
- 使用mysql的disctinct group by查询不重复记录
- mysql使用rand随机查询记录效率测试
- 使用log4net记录ibatis.net的SQL动态查询语句
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用mysql的disctinct group by查询不重复记录