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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Fetch Current logged i...
Power Apps
Unanswered

Fetch Current logged in user name in Dataverse table or in Model driven form

(1) ShareShare
ReportReport
Posted on by 74

HI

The requirement is, i need to verify the logged in user Info with the data available in my view or table(user people picker is from Microsoft Entra ID).

Need Logged in user name to create calculated column if Logged user is equal to User in table then display 1 else zero.

Similar way in the Model driven form as well.

I am unable to get the logged in user in Dataverse table or Model Driven App.

Please help ASAP.

 

Appreciate your quick response

 

Many Thanks in Advance

SG

 

 

I have the same question (0)
  • Jonathan Manrique Profile Picture
    2,687 on at

    Hi @SG013 

     

    To meet this requirement you must use JS, you can use the Web Client API provided by Dynamics 365. The Client API allows you to access a variety of information and perform operations within the context of the application.

    Then you need to create the JS and load it into the form and use the form's onload event

    Save this data in a field that you need and from there formulate your logic

     

    function onLoad(context) {
     // Obtener el contexto global
     var globalContext = Xrm.Utility.getGlobalContext();
     
     // Obtener el ID del usuario actual
     var userId = globalContext.userSettings.userId;
     console.log("ID del usuario actual:", userId);
     
     // Opcional: Obtener más información sobre el usuario
     // Nota: Asegúrate de reemplazar 'v9.1' con la versión correcta de tu API de Web
     var req = new XMLHttpRequest();
     req.open("GET", globalContext.getClientUrl() + "/api/data/v9.1/systemusers(" + userId + ")?$select=fullname,jobtitle", true);
     req.setRequestHeader("OData-MaxVersion", "4.0");
     req.setRequestHeader("OData-Version", "4.0");
     req.setRequestHeader("Accept", "application/json");
     req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
     req.onreadystatechange = function() {
     if (this.readyState === 4) {
     req.onreadystatechange = null;
     if (this.status === 200) {
     var result = JSON.parse(this.response);
     var fullName = result["fullname"];
     var jobTitle = result["jobtitle"];
     console.log("Nombre completo del usuario:", fullName);
     console.log("Título del trabajo del usuario:", jobTitle);
     } else {
     console.log("Error al obtener información del usuario:", this.statusText);
     }
     }
     };
     req.send();
    }

     

  • AllanDeCastro Profile Picture
    412 Most Valuable Professional on at

    Hello @SG013 ,

    Would love to understand the whole scenario as maybe some existing fields are enough for you (createdby, modifiedby..).
    You can create a JavaScript Web Resource to get the logged-in user's information and add it to the form.

    function getLoggedInUser(executionContext) {
     var formContext = executionContext.getFormContext();
     var userId = Xrm.Utility.getGlobalContext().userSettings.userId;
     var userName = Xrm.Utility.getGlobalContext().userSettings.userName;
    
     // Set these values on the form or use them as needed
     formContext.getAttribute("fieldname").setValue(userName); // Assuming you have a field to store the username, here fieldname is a basic string btu you can also you a lookup data type
    }


    @Jmanriquerios : Using XMLHttpRequest is not recommended.


  • Jonathan Manrique Profile Picture
    2,687 on at

    Thansk @AllanDeCastro 

  • Shashank Bhide Profile Picture
    942 Moderator on at

    Call WhoAmI endpoint

     

    <SERVER>/api/data/v9.2/WhoAmI

  • Geetha4 Profile Picture
    2 on at

    Thanks for the response!

     My concern was to set a field (Is Current user) in my table to display the current logged in user as 1 if the current user matches with user Column (Lookup from Microsoft Entra ID/AADUser Table) and not from user table .

    And this should be reflected on table load.

  • Shashank Bhide Profile Picture
    942 Moderator on at

    @Geetha4 - Sounds like you need a retrieve plugin on the read of your "table" where you can return 1 or 0 based on the logic. However, that may have some perf implications as the plugin will execute for every row, alternatively you can create a custom screen to show the desired values.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard