cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Auto populate first dropdown value in the second dropdown in a customized gallery

Hi, 
I need a help with my powerapps Gallery, I have a customized gallery named "TripRecord" which also has 4 input fields, '+' and 'X' icons to add and delete a record.

input1- from location: dropdown, input2- To location: dropdown, input3- from date: datepicker, input4- to date: datepicker

 

what I want the gallery to do as below,

ex: consider the first record items is selected as below

fromdropdown1: Canada   Todropdown1: Mexico 

Fromdate1: 1/01/2020        todate1: 2/01/2020

 

and in the second record of the gallery, I want the Fromdropdown2 to get the value from Todropdown1 to be auto populated as below and let the user choose the values for the rest of the fields.

Fromdropdown2: Mexico  (auto populate Mexico)   todropdown2

Fromdate2:        todate2

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Hi @ZenHen :

I've made a test but it worked well.

20.gif

Please try adding a unique identifier "ID" to TripRecord.For Example:

ClearCollect(TripRecord,{Input1:"",Input2:"",Input3:Today(),Input4:Today()})

1\Add a gallery and set it's Items proeprty to(Sort the items displayed in the Gallery in ascending order😞

Sort(TripRecord,ID)

2\Add two drop down controls into this gallery(fromdropdown/Todropdown)

Set fromdropdown:

Items

["","Canada","Mexico","US","UK"]

OnChange

Patch(TripRecord,ThisItem,{Input1:fromdropdown.SelectedText.Value})

Default

ThisItem.Input1

Set Todropdown:

Items

["","Canada","Mexico","US","UK"]

OnChange

Patch(TripRecord,ThisItem,{Input2:Todropdown.SelectedText.Value})

Default

ThisItem.Input2

3\Add two date picker controls into this gallery(Fromdate/Todate)

Set Fromdate

OnChange

Patch(TripRecord,ThisItem,{Input3:Fromdate.SelectedDate})

DefaultDate

ThisItem.Input3

Set Todate

OnChange

Patch(TripRecord,ThisItem,{Input4:todate.SelectedDate})

DefaultDate

ThisItem.Input4

4\Add an "Add" icon and an "Rubbish-bin" icon

Add icon-OnSelect

Patch(TripRecord,Defaults(TripRecord),{ID:Last(Sort(TripRecord,ID)).ID+1,Input1:Todropdown.SelectedText.Value})

Rubbish-bin icon-OnSelect

Remove(TripRecord,ThisItem)

The principle of my solution is:
1: When adding a new item: Use the Todropdown.SelectedText.Value of the current record as the value of the Input1 field of the new record.
2: When displayed, the default value of the To drop-down box of the new item is the value of Input1, so it will display the Todropdown.SelectedText.Value of the previous record by default

Best Regards,

Bof

 

View solution in original post

4 REPLIES 4
Highlighted
Community Support
Community Support

Hi @ZenHen :

I've made a test for your reference:

My data source-TripRecord:

  • ID-number
  • Input1-Text
  • Input2-Text
  • Input3-Date
  • Input4-Date
ClearCollect(TripRecord,{Input1:"",Input2:"",Input3:Today(),Input4:Today()})

1\Add a gallery and set it's Items proeprty to:

TripRecord

2\Add two drop down controls into this gallery(fromdropdown/Todropdown)

Set fromdropdown:

Items

["","Canada","Mexico","US","UK"]

OnChange

Patch(TripRecord,ThisItem,{Input1:fromdropdown.SelectedText.Value})

Default

ThisItem.Input1

Set Todropdown:

Items

 

["","Canada","Mexico","US","UK"]

 

OnChange

 

Patch(TripRecord,ThisItem,{Input2:Todropdown.SelectedText.Value})

 

Default

 

ThisItem.Input2

 

3\Add two date picker controls into this gallery(Fromdate/Todate)

Set Fromdate

OnChange

Patch(TripRecord,ThisItem,{Input3:Fromdate.SelectedDate})

DefaultDate

ThisItem.Input3

Set Todate

OnChange

 

Patch(TripRecord,ThisItem,{Input4:todate.SelectedDate})

 

DefaultDate

 

ThisItem.Input4

4\Add an "Add" icon and an "Rubbish-bin" icon

Add icon-OnSelect

Patch(TripRecord,Defaults(TripRecord),{ID:CountRows(TripRecord)+1,Input1:Todropdown.SelectedText.Value})

Rubbish-bin icon-OnSelect

Remove(TripRecord,ThisItem)

Best Regards,

Bof

 

 

Highlighted

Hello Bof, 

 

Thankyou very much for your response, i followed your steps, but unfortunately it did not give me the result i wanted. i want the to country to be auto populated as from country in the second entry as shown in the below image.

ZenHen_0-1600254696487.png

@v-bofeng-msft 

Highlighted

Hi @ZenHen :

I've made a test but it worked well.

20.gif

Please try adding a unique identifier "ID" to TripRecord.For Example:

ClearCollect(TripRecord,{Input1:"",Input2:"",Input3:Today(),Input4:Today()})

1\Add a gallery and set it's Items proeprty to(Sort the items displayed in the Gallery in ascending order😞

Sort(TripRecord,ID)

2\Add two drop down controls into this gallery(fromdropdown/Todropdown)

Set fromdropdown:

Items

["","Canada","Mexico","US","UK"]

OnChange

Patch(TripRecord,ThisItem,{Input1:fromdropdown.SelectedText.Value})

Default

ThisItem.Input1

Set Todropdown:

Items

["","Canada","Mexico","US","UK"]

OnChange

Patch(TripRecord,ThisItem,{Input2:Todropdown.SelectedText.Value})

Default

ThisItem.Input2

3\Add two date picker controls into this gallery(Fromdate/Todate)

Set Fromdate

OnChange

Patch(TripRecord,ThisItem,{Input3:Fromdate.SelectedDate})

DefaultDate

ThisItem.Input3

Set Todate

OnChange

Patch(TripRecord,ThisItem,{Input4:todate.SelectedDate})

DefaultDate

ThisItem.Input4

4\Add an "Add" icon and an "Rubbish-bin" icon

Add icon-OnSelect

Patch(TripRecord,Defaults(TripRecord),{ID:Last(Sort(TripRecord,ID)).ID+1,Input1:Todropdown.SelectedText.Value})

Rubbish-bin icon-OnSelect

Remove(TripRecord,ThisItem)

The principle of my solution is:
1: When adding a new item: Use the Todropdown.SelectedText.Value of the current record as the value of the Input1 field of the new record.
2: When displayed, the default value of the To drop-down box of the new item is the value of Input1, so it will display the Todropdown.SelectedText.Value of the previous record by default

Best Regards,

Bof

 

View solution in original post

Highlighted

That worked Bof, Thats a million. @v-bofeng-msft 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Users online (9,032)