如何编写用于在crm 2011中获取用户名(而非所有者)的javascript函数。

最佳答案

如果您是指FullName记录的SystemUser属性,则可以使用以下功能:

function getCurrentUserFullName() {
    var serverUrl;
    if (Xrm.Page.context.getClientUrl !== undefined) {
        serverUrl = Xrm.Page.context.getClientUrl();
    } else {
        serverUrl = Xrm.Page.context.getServerUrl();
    }
    var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
    var userRequest = new XMLHttpRequest();
    userRequest.open("GET", ODataPath + "/SystemUserSet(guid'" + Xrm.Page.context.getUserId() + "')", false);
    userRequest.setRequestHeader("Accept", "application/json");
    userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    userRequest.send();
    if (userRequest.status === 200) {
        var retrievedUser = JSON.parse(userRequest.responseText).d;
        var userFullName = retrievedUser.FullName;
        return userFullName;
    }
    else {
        return "error";
    }
}

参考:CRM Answers - Get current user's full name with a synchronous call

关于dynamics-crm-2011 - 如何获得thr crm 2011的用户名?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16031886/

10-12 03:44