web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get the Logged in user id (email) from javascript

(0) ShareShare
ReportReport
Posted on by 265

Hi,

As all of you aware that the current api being depreciated and the new Web API for DynamicsCRM is on the way. We have a wrote one javascript to fetch currently logged in user id. ie. The user name(email) which is used for login. We successfully consumed the old API and able to get the logged in user user name. Can some one help on doing the same in the Web API. Below is the sample code i have used.

var url = serverUrl + "/api/data/v8.2";
    var userRequest = new XMLHttpRequest();
    userRequest.open("GET", url + "/systemusers?$filter=ownerid(" + Xrm.Page.context.getUserId().replace("{","").replace("}","") + ")", false);
alert(url + "/systemusers?$filter=ownerid(" + Xrm.Page.context.getUserId().replace("{","").replace("}","") + ")");
    userRequest.setRequestHeader("Accept", "application/json");
    userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    userRequest.setRequestHeader("OData-MaxVersion", "4.0");
    userRequest.setRequestHeader("OData-Version", "4.0");
    userRequest.onreadystatechange = function () {
        if (this.readyState == 4) {
            userRequest.onreadystatechange = null;
            alert(this.status);
            if (this.status == 200) {
                var data = JSON.parse(this.response).d;
                if (data && data.value) {
                    var userName = retrievedUser.InternalEMailAddress;
                    return userName;
                }
            }
            else {
                 return "error";
            }
        }
    };
    userRequest.send(null);

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    Try

    "/systemusers(Xrm.Page.context.getUserId().replace("{","").replace("}",""))


  • Community Member Profile Picture
    on at

    Use CRM Restbuilder to create full code:

    github.com/.../releases

  • Suggested answer
    venkateshmpr Profile Picture
    265 on at

    Thanks for Your Help Gopalan Bhuvanesh... It works perfectly...!

    Thanks and Regards

    Venkatesan

  • venkateshmpr Profile Picture
    265 on at

    Thanks for Your Help Mohd Saad Akhtar... The solution which is provided by Gopalan Bhuvanesh works perfectly.

    Thanks and Regards

    Venkatesan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans