【问题标题】:User Impersonation using Web API使用 Web API 进行用户模拟
【发布时间】:2020-06-02 16:04:52
【问题描述】:

如何代表其他用户检索记录。

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 dynamics-crm-365 dynamics-crm-webapi


    【解决方案1】:

    我知道我们可以通过传递MSCRMCallerID 标头来使用XMLHttpRequest 进行模拟。不确定我们是否可以在Xrm.WebApi 中实现相同的效果。

    这是我的 Prod 代码,在来自 HTML 网络资源的管理员模拟下执行一些更新/分配操作。

    var entity = {};
    entity["ownerid@odata.bind"] = "/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 不能接受请求标头。

    Documentation 说:

    有两种方法可以模拟用户,这两种方法都可以通过传入带有相应用户 ID 的标头来实现。

    首选:根据用户的 Azure Active Directory (AAD) 对象 ID 模拟用户,方法是将该值与标头 CallerObjectId 一起传递。
    旧版:要根据用户的 systemuserid 模拟用户,您可以利用 MSCRMCallerID 和相应的 guid 值。

    【讨论】:

    • 感谢您的宝贵时间。啊!那是对的。但期待 Xrm.WebApi。
    • @Sidhu 上次我检查时它不存在。
    • 感谢您抽出宝贵时间@Arun。我正在检查这个。
    • @Sidhu 怎么样?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 2011-12-04
    相关资源
    最近更新 更多