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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans