web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Community Member Profile Picture
    on at
    RE: TypeError: Cannot read property 'getUserId'

    Thank You Andrew.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: TypeError: Cannot read property 'getUserId'

    Hello,

    Replace

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

    with

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

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans