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
Thank You Andrew.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Andrés Arias as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Aric Levin - MVP 2 Moderator
MA-04060624-0 1