cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
alex5p
Level: Powered On

Getting the department/office location of a user

I am trying to save the user's office location or department . Before I was using office365 connected to a dropdown and just used

 

Department: rbName.Selected.officeLocation

to save the officelocation to a sharepoint field. I wanted to remove the dropdown menu with all the employees names and have the system automatically know who the user is using the referral system.

 

I am currently using

 Set(varUserEmail, User().Email); Set(varFullName, User().FullName); 

 

to save the user's email and name. but I don't see anything for the department/office location. Is there anyway to save the location automatically like i am doing with the email and full name?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
alex5p
Level: Powered On

Re: Getting the department/office location of a user

@PowerAddict Thanks for all you help.

 

I just used 

Department:Office365Users.MyProfile().Department

 and that worked for me. I am in a rush for now so I am just going to use that temporarily until I figure out the other way. I would prefer not to have to make users use office365users.  

View solution in original post

20 REPLIES 20
PowerAddict
Level 10

Re: Getting the department/office location of a user

Yes, for that you need to fetch the user in the following way: 

 

Set(currUser, Lookup(Users, 'Primary Email' = User().Email) OR

Set(currUser, Lookup(Users, 'Full Name' = User().FullName)

 

Then you can use the following to get Department: 

 

Department: currUser.officeLocation

 

Let me know if this works.

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

alex5p
Level: Powered On

Re: Getting the department/office location of a user

I got an error saying 

 

The function lookup has some invalid arguments

 

I put the code in the App Section and set the code on OnStart. Is that correct place to put the code?

 

 

2019-11-12 11_02_09-ESSA Referral System - Saved (Unpublished) - PowerApps.png

PowerAddict
Level 10

Re: Getting the department/office location of a user

Replace the Primary Email with the field that stores the email in the Users entity. Or use the full name option that I shared. Let me know if that works. 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

alex5p
Level: Powered On

Re: Getting the department/office location of a user

4.png

 

I save the user's full name on a sharepoint field called ReferredBy. Is Users suppose to be something else ?

PowerAddict
Level 10

Re: Getting the department/office location of a user

If your users are stored in a SharePoint list, you need to replace the Users with where you have your users. 

 

So, something like: 

 

Set(currUser, "SharePointList", 'Referred By' = User().FullName)

 

Let me know if this works. If not, dont worry, will help you get to the solution!

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

alex5p
Level: Powered On

Re: Getting the department/office location of a user

It looks like the first part worked ,but saving the actual department doesn't seem to work. When I try to patch the field to save it to the department field in my share point list. 

 

12.png9.png

 

Thank you for your help

PowerAddict
Level 10

Re: Getting the department/office location of a user

That should be easy. Can you show me your Patch function? 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

alex5p
Level: Powered On

Re: Getting the department/office location of a user

 

Patch(
ReferralSystem,
Defaults(ReferralSystem),
{
Title: CustomerName.Text,
CustomerName: CustomerName.Text,
ContactName: contactName.Text,
PhoneNumber: formatphone.Text,
Email: emailText.Text,
BestToCall: bestTToCall.Text,
Address: Address.Text,
City: City.Text,
Zip: Zip.Text,
DateOfReferral: 'Date of Referral'.SelectedDate,
DateofReferralText: 'Date of Referral'.SelectedDate,
State: states.SelectedText,
//ReferredBy: rbName.Selected.displayName,
ReferredBy: User().FullName,
Details: details.Text,
AreaOfInterest: Label38.Text,
AppointmentTime: Appointmenttime.Text,
AppointmentLocation: AppointmentLocation.Text,
LoanAccountType: TextInput3.Text,
EstimatedClosingDate: DatePicker1.SelectedDate,
AppointmentDate: Appointmentdate.SelectedDate,
//Department: rbName.Selected.officeLocation,
// Department: currUser.officeLocation,
//userEmail: rbName.Selected.mail,
userEmail: User().Email,
AppraisalOrdered: aOrdered.SelectedText,

Billboard:LookUp(col,ID=1,forPromoMenu.SelectedText),
Newspaper:LookUp(col,ID=2,forPromoMenu.SelectedText),
Builder:LookUp(col,ID=3, forPromoMenu.SelectedText),
Letter_Postcard:LookUp(col,ID=4,forPromoMenu.SelectedText),
BranchSignage:LookUp(col,ID=5,forPromoMenu.SelectedText),
Radio:LookUp(col,ID=6,forPromoMenu.SelectedText),
Website:LookUp(col,ID=7,forPromoMenu.SelectedText),
GoogleBing:LookUp(col,ID=8,forPromoMenu.SelectedText),
Realtor:LookUp(col,ID=9,forPromoMenu.SelectedText),
EmailPromo:LookUp(col,ID=10,forPromoMenu.SelectedText),
Other:LookUp(col,ID=11,forPromoMenu.SelectedText),
CustomerReferral:LookUp(col,ID=12,forPromoMenu.SelectedText),
ExistingCustomer:LookUp(col,ID=13,forPromoMenu.SelectedText),


ReferredToName: LookUp(
referredPeople,
!IsBlank(value),
value),
BackupName: LookUp(
backupPeople,
!IsBlank(value),
value),
ReferEmail: LookUp(
referredPeopleEmail,
!IsBlank(value),
value),
BackupEmail: LookUp(
backupPeopleEmail,
!IsBlank(value),
value)



}
PowerAddict
Level 10

Re: Getting the department/office location of a user

From the error image you shared, seemed like the error is with the Department field. But in the Patch function, you have your department field commented out. Are you still getting the error in the Patch function? If so, can you tell me what the error is in the Patch function now without the Description field? 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,346)