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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

TypeError: Cannot read property 'getUserId'

(0) ShareShare
ReportReport
Posted on by

Hello Great folks,


New to MSD CRM. Learning customizations at the moment. 

I wrote a simple code in Javascript to read the current userid and I am the following error:


TypeError: Cannot read property 'getUserId' of undefined at getUserId (myname.crm.dynamics.com/.../new_JSStaff-FormType) at staffDisplayFormType (myname.crm.dynamics.com/.../new_JSStaff-FormType) at eval (eval at RunHandlerInternal (myname.crm.dynamics.com/.../ClientApiWrapper.aspx), <anonymous>:1:1) at RunHandlerInternal (myname.crm.dynamics.com/.../ClientApiWrapper.aspx) at RunHandlers (myname.crm.dynamics.com/.../ClientApiWrapper.aspx) at OnScriptTagLoaded (myname.crm.dynamics.com/.../ClientApiWrapper.aspx) at myname.crm.dynamics.com/.../ClientApiWrapper.aspx

Code:

 function staffDisplayFormType()
{  
   var formType = Xrm.Page.ui.getFormType();

   switch (formType)
{
              case 1: alert('Form type is Create');
      
              var userId = getUserIdentity();
    
              alert(userId);

               break;
   
               case 2: alert('Form type is Update');
               break;
     
               case 3: alert('Form type is Readonly');
               break;
   
              default:  document.write("unknown form type")


}
}

function getUserIdentity()
{
      var auserid = Xrm.Page.Context.getUserId();

      return auserid;

}



*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Replace

    var auserid = Xrm.Page.Context.getUserId();

    with

    var auserid = Xrm.Page.context.getUserId();

  • Community Member Profile Picture
    on at

    Thank You Andrew.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans