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 fetch logged in username in Javascript

(0) ShareShare
ReportReport
Posted on by 420

Hi All,

How to retrieve  the logged in username from "User" entity?  We need to retrieve this info in "Contact" entity form, using javascript , what is the parent child relationship pls help me with some code.

Regards

Felix

*This post is locked for comments

I have the same question (0)
  • MDoddio73 Profile Picture
    1,910 on at

    You can use the Xrm.Page.context.getUserId() method to get the System User GUID. You would then need to use OData to retrieve the User Name.

  • Verified answer
    jlattimer Profile Picture
    24,562 on at

    Something like this:

    function GetName() {
        var odataSelect = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/OrganizationData.svc/SystemUserSet?$select=FullName&$filter=SystemUserId eq guid'" + Xrm.Page.context.getUserId() + "'";
        var retrieveReq = new XMLHttpRequest();
        retrieveReq.open("GET", odataSelect, false);
        retrieveReq.setRequestHeader("Accept", "application/json");
        retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieveReq.onreadystatechange = function () {
            getResult(this);
        };
        retrieveReq.send();
    }
    
    function getResult(retrieveReq) {
        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;
                var retrievedValue = retrieved.results[0].FullName;
                alert(retrievedValue);
            }
        }
    }
    
  • Felix Xavier Profile Picture
    420 on at

    Thanks a lot Jason for your reply , its working well.

    Regards

    Felix

  • Felix Xavier Profile Picture
    420 on at

    Thank you Doddio

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