web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Select between value a...
Power Apps
Answered

Select between value already in a filed or a value based on another combo box

(0) ShareShare
ReportReport
Posted on by 316

Hi,

I have a combo box (email) that gets its value from another field (Display Name).  I am trying to modify the DefaultSelectedItem with an IF statement so that if there is a record that is edited, it will select the current email address stored in the record.  However, if the record is 'New', then it will populate from the 'Display Name' combo box.

Both of these statements work perfectly by themselves:

 

If(varSecMode = "Edit",
 {Value:ThisItem.EmailAddress},
 (Office365Users.SearchUser({searchTerm: ComboBox6.Selected.DisplayName}).Mail);
)

 

But if I put them in an IF statement, I get a {value:ThisItem.EmailAddress} does not work.  Can anyone advise why this wont work?

Cheers,

Geoff.

Categories:
  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @Iamglt ,

     

    Could you tell me:

    Is your combo box control in the edit form control?

    What's varSecMode? 

    Do you want the combo box control to display the data in the form when the form is in the edit state (the data of the form comes from the gallery control or data source?)

    Do you want the data to come from Office365Users.SearchUser when the state of the form control is new?

    Do you want the data to be displayed in the combo box control by default?

     

    If my assumptions are correct, the point is to use Table({Mail:ThisItem.EmailAddress}) instead of {Value:ThisItem.EmailAddress}.

     

    I've made a test for your reference:

    1\ This is my list 'LIST68'

    v-xiaochen-msft_0-1612344071559.png

     

     

    2\ Add a gallery control 'Gallery1' and set its Items prperty to:

    LIST68

     

    3\ Add an edit form control 'Form1' and set its DataSource property to: 

    LIST68 

     

    Set its Item property to:

    Gallery1.Selected

     

    4\ Add a combo box control 'ComboBox6' and set its Items property to:

    LIST68

     

    5\ Insert a combo box control into form and set its Items property to:

    If(Form1.Mode=FormMode.Edit,Table({Mail:ThisItem.EmailAddress}),Office365Users.SearchUser({searchTerm:ComboBox6.Selected.DisplayName}).Mail)

     

    Set the combo box control's DefaultSelectedItems property to:

    If(Form1.Mode=FormMode.Edit,Table({Mail:ThisItem.EmailAddress}),Office365Users.SearchUser({searchTerm:ComboBox6.Selected.DisplayName}).Mail)

     

    6\ The result is as follows:

    Now the status of the form is New

    188.PNG

    Now the status of the form is Edit

    189.PNG

     

    Best Regards,
    Wearsky
    If my post helps, then please consider Accept it as the solution to help others. Thanks.

  • Iamglt Profile Picture
    316 on at

    Hi Wearsky,

     

    Thanks for your response with this (I really appreciate your help) - here are the answers to your questions:

     

    varSecMode is a variable I set depending on the form being in Edit or New mode for the save.  As the Comboboxes wont save their data with submit form, I have to patch everything manually:

    Set(varSecMode, "Edit"); EditForm(Form1)

    And then to save the form, I use the following code:

    If(varSecMode = "Edit",
     Patch(
     NewEmployeeAccess,
     {FullName: ComboBox6.Selected.DisplayName},
     {EmailAddress: ComboBox11.Selected.Mail},
     {HRAccess: If(Checkbox14.Value = true,"Yes","No")},
     {SecurityAccess: If(Checkbox15.Value = true,"Yes","No")},
     {AdminAccess: If(Checkbox16.Value = true,"Yes","No")}
     );,
     Patch(
     NewEmployeeAccess,
     Defaults(NewEmployeeAccess),
     {FullName: ComboBox6.Selected.DisplayName},
     {EmailAddress: ComboBox11.Selected.Mail},
     {HRAccess: If(Checkbox14.Value = true,"Yes","No")},
     {SecurityAccess: If(Checkbox15.Value = true,"Yes","No")},
     {AdminAccess: If(Checkbox16.Value = true,"Yes","No")}
     ); 
    )

    The above information you posted works, but I am not using a gallery, I am using a datatable, so I don't think datatable1.selected will work.  Ideally I am trying to create a list of users and what they have access to:

    Iamglt_0-1612389058282.png

    So I either want to be able to select a user from a list and edit their details, or create a new user by searching for the username and add them to the list.  I am also trying to stop it from adding blanks (i.e. Blanks Names) and stopping duplicate entries (i.e. if someone tries to add a user that already exists, it will search the list and advise that the user already exists). 

    Any assistance your could provide would be greatly appreciated.

    Cheers,

    Geoff.

     

  • Verified answer
    v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @Iamglt ,

     

    According to your description, I know that you use the data table control instead of the gallery control.

    But I don't quite understand why datatable1.selected will not work.

    Please refer to the figure below. After I set the Item property of the form control to datatable1.selected, it worked.

    190.PNG

     

    So , after selecting a record in the datatable, the form should display detailed information(Used to modify this record)?

    If you create a new record (the form is in the new state at this time), do you want the email to be displayed based on Office365Users.SearchUser?

    If my assumptions are correct,I think the above solution can meet your needs.

    Maybe I understand it wrong, please tell me what is missing in my solution.

     

    Best Regards,
    Wearsky
    If my post helps, then please consider Accept it as the solution to help others. Thanks.

  • Iamglt Profile Picture
    316 on at

    Hi Wearsky,

     

    Indeed it does work  - I got it working this morning.

     

    Thank you so much for your help.

     

    Cheers,

    Geoff.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 312

#3
Mohsin Ali Profile Picture

Mohsin Ali 252

Last 30 days Overall leaderboard