cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Add Extra field to User()

Hello Guys,

Please how do i add extra field to a user so that i can call that detail of the current user at Onstart of an app
StaffName which is a person or group field to have an extra  field Staff ID 
so i call Staff.StaffID onstart of an App into a varialble
or load from   Office365Users.StaffID 

Please help


9 REPLIES 9
Highlighted
Super User
Super User

Re: Add Extra field to User()

@abieba 

To do this you'll have to create a global variable holding the information of User().  Put this code in the OnStart property of your app.

 

Set(
currentUser,
{
FullName: User().FullName,
Email: User().Email,
Image: User().Image
Additional_Field_Name: put_your_code_here
}
)

 

To access information stored in the variable you would write this code

 

currentUser.FullName

 

And the result would be something like

 

John Smith

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Resolver III
Resolver III

Re: Add Extra field to User()

@mdevaney 

 

I had no idea you could do this with variables! Awesome stuff.

Highlighted
Helper III
Helper III

Re: Add Extra field to User()

Hello @mdevaney 
Ok so looking at this now  i have a list called staffProfile and a column there called staffID 
How do i then achieve this

Set(
currentUser,
{
FullName: User().FullName,
Email: User().Email,
Image: User().Image
StaffID: pull_StaffID column from that The CurrentUser
}
)




Highlighted
Super User
Super User

Re: Add Extra field to User()

@abieba 

What column does the currentUser variable and your list have in common?  I will need this info to propose a solution.

Highlighted
Helper III
Helper III

Re: Add Extra field to User()

StaffName and its a person or group field

Highlighted
Super User
Super User

Re: Add Extra field to User()

@abieba 

For clarificiation, why do you want to pull-in the column StaffName?  What data are you using from this People or Group data type?  Is it more than just the DisplayName?

Highlighted
Helper III
Helper III

Re: Add Extra field to User()

I am pulling email as well

Pix.JPG

To resolve my issue i want to be able to add my own field to these list of field gotten from Office365Users.MyProfile(), so i could have.  

Office365Users.MyProfile().StaffID
Office365Users.MyProfile().StaffCategory

Currently i have a  list staffprofile with 
Pix2.JPG

Currently when i am creating a form and there is a field called staffID or staff category, i create a gallery in a separate screen and call the staffprofile list and filter current user with StaffName.email, that way i get the staffID and category of the current user
into lets say StaffIDDatacardValue  and StaffCatDatardValue


when i get to the datacard in the form that has  staff ID, in the text property of the formdatacard with i call StaffIDDatacardValue.Text then in the Staff Category form datacard i call StaffDataCardValue.Text    but its not been so effective doing this, i would like to have a case where on start of the application i call those two values into a varialbe so it loads Onstart 

How would you advise i best resolve this issue

Highlighted
Super User
Super User

Re: Add Extra field to User()

@abieba 

 

My first suggestion would be to replace the Staff Name column in your StaffList with Staff Email instead.  Emails are unique to the employee whereas name might not be.  An example is: there could be two employees named 'John Smith'.  However, their email addresses would have to be different.  Matching on email ensures the correct match will be made between StaffList and Office365Users.MyProfileV2().

 

Capture.PNG

 

Then you'll want to put this code into the OnStart property of your app.  This code collects the user profile in userCollection.  Then we ADDCOLUMNS Staff ID and Staff Category with the matching values in your StaffList by using LOOKUP and joining on the Email/Mail fields.  Finally, we create a global variable currentUser from the only record in userCollection because we want to store it as record, not a table.

 

 

ClearCollect(userCollection,Office365Users.MyProfileV2());
AddColumns(
userCollection,
"Staff ID",LookUp(StaffList,'Staff Email' = userCollection[@mail],'Staff ID'),
"Staff Category",LookUp(StaffList,'Staff Email' = userCollection[@mail],'Staff Category')
);
Set(currentUser,First(userCollection));

 

I've thought about it alot and think this will suit your purposes.  Give it a try and let me know.

 

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

 

 

Highlighted
Helper III
Helper III

Re: Add Extra field to User()

Hello @mdevaney 

So how do i call the Staff ID of the of the current user (currentuser2) is what i used for the collection.

//Refresh('ZOSL Contractor Registration Database');

Refresh('Leave Balance List');
Refresh('Staff Outstation Form');
NewForm(Form1);

Set(CurrentUserEmail, User().Email);
Set(CurrentUserName, User().FullName);
Filter('Leave Balance List', 'Staff Name'.Email = CurrentUserEmail); 
Set(CurrentUser, 
{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
    Claims:"i:0#.f|membership|" & User().FullName,
    Department:"",
    DisplayName:User().FullName,
    Email:User().Email,
    JobTitle:"",
    Picture:""
   });
//Filter('ZOSL Contractor Registration Database', FilterTextBox.Text in CompanyName);
Set(HSE , 1);
Set(BasicInformation , 1);
Set(BankInformation, 1);
Set(formsview, 0);
Set(ViewSwitch, 0);
//Navigate('Vendor List Page');
Set(contractorfilter, 0);

ClearCollect(userCollection,Office365Users.MyProfileV2());
AddColumns( userCollection,
    "Staff ID",LookUp('Leave Balance List','Staff Email' = userCollection[@mail], 'Staff ID'),
    "Staff Category",LookUp('Leave Balance List','Staff Email' = userCollection[@mail],'Category')
);
Set(CurrentUser2,First(userCollection));

This is my current code Onstart
The Code in red is the code we are looking at.

 

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,395)