Search code examples
active-directorysharepoint-onlinepowerappspowerapps-canvaspowerapps-formula

Can we get Active Directory property named Employee ID using Office365Users connector inside Power App


Inside our active directory we have a property named "Employee ID" as follow:-

enter image description here

so inside our PowerApp form i want to get the value of this property,,, but i checked the Office365Users connector @ https://learn.microsoft.com/en-us/powerapps/maker/canvas-apps/connections/connection-office365-users seems it does not provide such a data.. so how i can get the Employee ID property inside our PowerApp form? this ID is different than the ID which we can get using this formula Office365Users.MyProfile().Id which will return the internal GUID of the user, and not the number shown above.

Thanks in advance for any help.


Solution

  • Currently (As of 2021-09-27), there is no Out of the box connector for Power Apps that will get you employeeId. The reason is that we need to query the beta version of Microsoft Graph, as it is not query-able in the version 1.0 of the endpoint. There is hope, the new Office 365 Users Connector has a new version of Get my profile (V2) that queries the new version of the Graph interface, and allows us to select employeeId, as well as almost everything else available. The downside is that it returns a GraphUser_V1 object. So, even though the API call returns the employeeId, since Power Apps is Strongly Typed, we cannot reference employeeId as it's not a part of the GraphUser_V1 object.

    Power Apps may not be able to pull the value, but Power Automate can. As a POC to get you started:

    1. In Power Apps, create a button with the Action being running a Power Automate Flow.
    2. Create a new flow "Power Apps button" called "GetEmployeeId".
    3. In Power Automate, create a new step: Get my profile (V2).
      • Under advanced options set Select fields to employeeId
    4. Create a new step: Parse JSON
      • Set Content to the body of Get my profile (V2): @{outputs('Get_my_profile_(V2)')?['body']}
      • Set Schema to:
    {
        "type": "object",
        "properties": {
            "@@odata.context": {
                "type": "string"
            },
            "@@odata.id": {
                "type": "string"
            },
            "employeeId": {
                "type": "string"
            }
        }
    }
    
    1. Create a new step: Respond to a PowerApp or flow
    2. Add an output type Text:
      • Enter title : EmployeeId
      • Enter in a value to respond : @body('Parse_JSON')?['employeeId']
    3. Save the Power Automate flow and test it. You will have to approve O365 access permissions. The whole flow should look like this:

    Get EmployeeId Flow

    1. Back in Power Apps, Connect your new flow to the app.
    2. Set your Button1.OnSelect to: Set( varEmployeeID, GetEmployeeId.Run())
    3. Create a label with the Label1.Text set to: varEmployeeID.employeeid
    4. Run the app and click the button to test.