Forum Discussion
Retrieve Employee AD Job Title to SP List
I have an SP List I am using to manage access/permissions in a Power App.
The 'EmployeeName' is a Person/Group column.
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)
)
);
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.
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.
- PhishdawgBrass ContributorThis 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?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.