SOLVED

Retrieve Employee AD Job Title to SP List

Brass Contributor

I have an SP List I am using to manage access/permissions in a Power App.

The 'EmployeeName' is a Person/Group column.

Phishdawg_0-1692809629305.png


I am using the following code at 'OnStart' of my app to check to see if the employee is already active in the system, and if not add the employee.

Currently, if the employee is not in the system the code with add their name and email. Is there a way to also have the coding add their 'Job Title'?

With(
{wUserRecord: LookUp('Request List Admin',EmployeeName.Email=varLoggedInUser.Email)},
     Set(varUser, wUserRecord.EmployeeName);
     Set(varRole, wUserRecord.EmployeeRole.Value));

//If matching user is not found, insert a new user into the list
If(IsBlank(varRole),
      With(
          {wUserRecord:
      Patch(
               'Request List Admin',
                    Defaults('Request List Admin'),
    {
               EmployeeName: {
               '@odata.type':"Micorsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
               Claims: "i:0#.f|membership|"& varLoggedInUser.Email,
                     Department: "",
                     DisplayName: varLoggedInUser.FullName,
                     Email: varLoggedInUser.Email,
                     JobTitle: "",
                     Picture: ""
                }
          }
      )
},
Set(varUser, wUserRecord.EmployeeName);
Set(varRole, wUserRecord.EmployeeRole.Value)
)
);

5 Replies

@Phishdawg You cannot get the Job Title of currently logged in user using the Power Apps default User() function.

 

So, you will have to get that information using Office 365 Users connector. So first of all, add Office 365 Users connector (Data Source) in your app if not added already.

 

After adding the connector, write below formula at the start of App.OnStart: 

 

Set(gvUserObj, Office365Users.MyProfileV2());

 

Then you can update JobTitle column inside Patch function like: 

 

Patch(
	'Request List Admin',
	Defaults('Request List Admin'),
    {
		EmployeeName: {
            '@odata.type':"Micorsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|"& varLoggedInUser.Email,
            Department: "",
			DisplayName: varLoggedInUser.FullName,
			Email: varLoggedInUser.Email,
			JobTitle: "",
			Picture: ""
        },
		JobTitle: gvUserObj.jobTitle
    }
)

 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

This will place both formulas in the 'OnStart' - the job title formula ahead of the add new member formula.

Will this cause a functional conflict, causing one of both not to work due to the proximity to each other?
best response confirmed by Phishdawg (Brass Contributor)
Solution

@Phishdawg No, it will not cause any functional conflict and Job Title will be saved in the list without any issue.

 

In the first formula I suggested to add in App.OnStart only fetches the currently logged in user's information from Office 365 connector. So, it will not conflict with the 2nd formula.

 

By default in Power Apps, formulas run in the sequential manner. So, first it will fetch the user information from Office 365 connector and then it will check if user is available in the SharePoint list or not - and then add user information to SharePoint list. Try it once and let me know if you face any issues.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

I have an 'EmployeeRole' (Choice) column in the 'Roles List'.

I need this to auto-populate with one of for 'Roles', that will be used to control employee access and filtering.

I'm thinking of changing the column to a Text column and sending that information with the 'OnStart' formula.

Can I add an 'EmployeeRole' to the 'OnStart' formula and use an If statement to determine what is populated?

If("Manager" || "Supervisor" in gvUserObj, "Manager","User")

@Phishdawg Something like this should work in case of text column: 

 

Patch(
	'Request List Admin',
	Defaults('Request List Admin'),
    {
		EmployeeName: {
            '@odata.type':"Micorsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|"& varLoggedInUser.Email,
            Department: "",
			DisplayName: varLoggedInUser.FullName,
			Email: varLoggedInUser.Email,
			JobTitle: "",
			Picture: ""
        },
		JobTitle: gvUserObj.jobTitle,
		EmployeeRole: If("Manager" in gvUserObj.jobTitle || "Supervisor" in gvUserObj.jobTitle,"Manager","User")
    }
)

 


Please consider giving a Like if my post helped you in any way.

1 best response

Accepted Solutions
best response confirmed by Phishdawg (Brass Contributor)
Solution

@Phishdawg No, it will not cause any functional conflict and Job Title will be saved in the list without any issue.

 

In the first formula I suggested to add in App.OnStart only fetches the currently logged in user's information from Office 365 connector. So, it will not conflict with the 2nd formula.

 

By default in Power Apps, formulas run in the sequential manner. So, first it will fetch the user information from Office 365 connector and then it will check if user is available in the SharePoint list or not - and then add user information to SharePoint list. Try it once and let me know if you face any issues.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

View solution in original post