使用 OData 在 Dynamics CRM 中检索多个实体

Retrieve Multiple Enitiies in Dynamics CRM using OData

我有一个功能区按钮命令,它执行 javascript 函数并传入网格中的 selected 行。我正在遍历该列表以创建一个 $select 过滤器来发出 RetrieveMultiple 请求。 问题是每次我收到以下错误

400:错误请求:位置 1'Microsoft.Xrm.Sdk.Entity' 中不存在 属性 'id' 'id'

我尝试使用 id 而不是 Id,但我仍然遇到同样的错误。 我的代码如下

function approveMultipleApplications(selectedApplicationReferences) {
    if (selectedApplicationReferences && selectedApplicationReferences.length > 0) {
        var filter = '';
        for (var i = 0; i < selectedApplicationReferences.length; i++) {
            filter += '(id eq guid\'' + selectedApplicationReferences[i].Id + '\')';
            if (i < selectedApplicationReferences.length - 1) {
                filter += ' or ';
            }
        }

        var options = "$select=new_assessmentcount,new_requiredassessmentcount&$filter=" + filter;
        try {
            SDK.REST.retrieveMultipleRecords("new_application", options, retrieveApplicationsCallBack, function (error) {
                alert(error.message);
            }, retrieveComplete);
        }
        catch (ex) {
            Xrm.Utility.alertDialog('Something went wrong, please try again or contact your administrator ' + ex, null);
        }
    }
    else {
        Xrm.Utility.alertDialog('You must select at least one application to approve', null);
    }
}

selectedApplicationReferences[i].Id 采用这种格式 {guid-value} 感谢任何帮助或指导

错误消息非常准确:使用 LogicalNameId 而不是 Id。在你的情况下是 new_applicationId:

filter += '(new_applicationId eq guid\'' + selectedApplicationReferences[i].Id + '\')';

这可能有点混乱,因为数据库中实际上没有 Id 字段。如果你使用例如早期绑定 类,Id 字段是在幕后为您设置的,因此您可能感到困惑。 OData 端点未返回 Id 字段。