Updates for Web API in Dynamics 365 in version 9.0 (2)

In version 9.0, we don’t need to create any request for using Web API, instead, we will use built-in and pre-defined functions for using Web API. Now Dynamics 365 has a new library Xrm.WebApi and performs CRUD using Web API.

Retrieving record
Check Microsoft URL

var accountId = "DC1F674E-55F1-E711-A95F-000D3AF27163";
Xrm.WebApi.retrieveRecord("account", accountId, "?$select=name,revenue").then(
    function success(result) {
        alert("Retrieved values: Name: " + result.name + ", Revenue: " + result.revenue);
        // perform operations on record retrieval
    },
    function (error) {
        alert(error.message);
        // handle error conditions
    }
);

Retrieving records
Check Microsoft URL

Xrm.WebApi.retrieveMultipleRecords("contact", "?$select=firstname,lastname&$top=3&$filter=age lt 50").then(
    function success(result) {
        for (var i = 0; i < result.entities.length; i++) {
            alert(result.entities[i]);
        }                    
        // perform additional operations on retrieved records
    },
    function (error) {
        alert(error.message);
        // handle error conditions
    }
);

Retrieving records by fetch XML

function retrieveMultipleContacts(executioncontext) {
var formContext = executioncontext.getFormContext();
var contactId = formContext.data.entity.getId();
var fetchContacts = "<fetch version='1.0' output-format='xmlplatform'
mapping='logical' distinct='false'>" +
"<entity name='contact' >" +
"<attribute name='fullname' />" +
"<attribute name='telephone1' />" +
"<attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='parentcustomerid' operator='eq'
uitype='account' value ='" + accountId + "' />" +
"</filter>" +
"</entity >" +
"</fetch > ";
Xrm.WebApi.retrieveMultipleRecords("contact", "fetchXml= " +
fetchContacts).then(
function success(result) {
for (var i = 0; i < result.entities.length; i++) {
alert(result.entities[i]);
}
},
function (error) {
alert(error.message);
});
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值