Wednesday, December 14, 2016

Gets the current user and enters string into specified field

function loggedUser(field) {
    var user = Xrm.Page.context.getUserId();
    var userId = user.substring(1, 37);
    var serverUrl = document.location.protocol;
    serverUrl += "//" + document.location.host;
    serverUrl += "/" + Xrm.Page.context.getOrgUniqueName();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
    var ODATA_EntityCollection = "/SystemUserSet";
    var ODATA_Query = "(guid\'" + userId + "')";
    var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query;

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: ODATA_Final_url,
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            var userName = data.d.FullName;
            Xrm.Page.getAttribute(field).setSubmitMode("always");
            Xrm.Page.getAttribute(field).setValue(userName);
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert('Error: ' + ODATA_Final_url);

        }
    });

}

No comments:

Post a Comment

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...