Announcements
No record found.
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
Hello,
Replace
var auserid = Xrm.Page.Context.getUserId();
with
var auserid = Xrm.Page.context.getUserId();
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.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.