Notifications
Announcements
Hi,
How to retrieve current user name and email id in model driven app just like in canvas app(User().EmailId)? Any suggestion would be greatly appreciated.
Thank you,
Hi @aaedla ,
Check out the following link to get the details you are looking for:
https://carldesouza.com/dynamics-365-javascript-get-user/
Another link that shows the email address (internal email)
https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/126902/javascript---get-email-address-of-current-user/273544
Hello @aaedla
You can use below script
For Getting Logged in User Name :
var UserName = Xrm.Page.context.getUserName();
For getting Logged in User Email
var loggedinUserId = Xrm.Utility.getGlobalContext().userSettings.userId.replace("{","").replace("}",""); Xrm.WebApi.online.retrieveRecord("systemuser", loggedinUserId , "?$select=internalemailaddress").then( function success(result) { var internalemailaddress = result["internalemailaddress"]; }, function(error) { Xrm.Utility.alertDialog(error.message); } );
Please mark as Answer if it is helpful and provide Kudos
Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLABlog : https://microsoftcrmtechie.blogspot.com
Hi @aaedla ,To get the Current logged-in User FullName :- --> var userSettings = Xrm.Utility.getGlobalContext().userSettings; --> var userFullName = userSettings.userName;To get the User email address we need to retrieve the User Record :- var userSettings = Xrm.Utility.getGlobalContext().userSettings;var userGUID = userSettings.userId;Xrm.WebApi.retrieveRecord("systemuser", userGUID, "?$select=internalemailaddress,fullname").then(function success(result) {console.log("Retrieved values: Name: " + result.internalemailaddress + ", Revenue: " + result.fullname);// perform operations on record retrieval},function (error) {console.log(error.message);// handle error conditions});Thanks,Manoj.If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to help others find it.
Thank you for your comments Rampprakash. I created js file and then uploaded to component library but I can see only on Chnage event, there is no OnLoad event. I want to auto populate user email id when form loads.Can you please elaborate with step by step?
Hello @aaedla,
1. Navigate to https://make.powerapps.com
2. Click Dataverse --> Expand Tables --> Open Table where you want to input your script
3. Click Forms --> Open Main Form --> Make Sure you are not clicking inside the WHITE BAR where the field is available, click Outside
SCREENSHOT FOR YOUR REFERENCE
Once you clicked at the Right side click events and input your onload Events 🙂
Hi Rampprakash,
OnLoad event is not showing up if I open table form from solution.
One more question: I am getting email id but how to auto populate email id in a field?
Thank you.
I didn't find any way to auto populate current user email id in a model driven application field. I used power automate to update the field.
Please let me know if there is any way to auto populate without using power automate flow.
@manojmane Is it Possible to add an If statement for the OnLoad event to only run if the field is blank? When opening a record, it will always change the field you configure the OnLoad event for, as the logged in user.
For those who don't want to use Javascript for this, I realized that the built-in Owner field always defaults to the current user, so I just set the default value to owner using a simple 1 step business rule. Even if owner changes, by choosing the "set default value" option, it shouldn't change when the owner does going forward.
Please mark this response as helpful or the solution if you found this helped you 🙂
Great solution!, Thank you a lot!
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.
In our never-ending quest to improve we are simplifying the forum hierarchy…
We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
WarrenBelz 711 Most Valuable Professional
Michael E. Gernaey 319 Super User 2025 Season 2
Power Platform 1919 268