使用Web API进行用户冒充

问题描述 投票:0回答:1

我如何能代表另一个用户检索记录。

Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name&$top=3").then(
    function success(result) {
        for (var i = 0; i < result.entities.length; i++) {
            console.log(result.entities[i]);
        }                    
        // perform additional operations on retrieved records
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);
dynamics-crm-365
1个回答
1
投票

我知道我们可以使用 XMLHttpRequest 顺带 MSCRMCallerID 头部。不确定我们是否能在 Xrm.WebApi.

这是我的Prod代码,在Admin冒充的情况下,从一个HTML网页资源中进行一些更新分配操作。

var entity = {};
entity["[email protected]"] = "/systemusers(" + currentUserId + ")";

var req = new XMLHttpRequest();
req.open("PATCH", parent.Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.1/new_customentity(" + opptyid + ")", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("MSCRMCallerID", "0AFB2F7E-D323-E511-80F0-C4346BAC29F0"); //CRM Admin impersoantion
req.onreadystatechange = function () {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 204) {
            //Success - No Return Data - Do Something
        } else {
            //Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send(JSON.stringify(entity));

更新

传递头部是唯一的方法,而且 Xrm.WebApi 不能接受请求头。

文件 说。

有两种方法可以冒充用户,这两种方法都可以通过传入一个带有相应用户ID的头来实现。

首选: 根据用户的Azure Active Directory (AAD)对象id,通过将该值与标题一起传递给用户来冒充用户。CallerObjectId. 遗产: 要根据用户的系统用户ID来冒充用户,你可以利用 MSCRMCallerID 与相应的指导值。

© www.soinside.com 2019 - 2024. All rights reserved.