3
votes

I am attempting to build an app with Microsoft powerapps that will be writing/reading data to/from an excel sheet.

I have created a form in powerapps from a table in the excel sheet. I am curious to know if anyone knows how to fill the data in a field based on a button selection on a previous screen.

As an example let's say the following fields are in the form; Location, Action, Item, Username.

This is what I am imaging and would like to do;

I would like the first two fields to be filled by selecting buttons on a previous screens instead of a drop down menu in the edit form view. the last two field can be filled by inputting text on a thirds screen.

The flow:

Screen1; presents two 4 locations in the form of buttons*doesn't necessarily have to be a button but function like one.

4 locations: NY, LA, AZ, LN

when users selects "NY" button, "NY" is filled/stored in to the "location" field in the form and the screen navigates to the next page where the user will select the actions.

Screen2; presents two 2 actions in the form of button.

2 Actions: remove, add

when users selects "remove" button, "remove" is filled/stored in to the "action" field in the form and the screen navigates to the next page where the user will fill the other two fields in a text field.

Screen3; has two text fields where user can fill in the rest of the information for item and user name. Location and Action should be prefilled at this point. When the user submits the form all data is submitted and a row is created in the excel table with all the information captured.

any information how to make a button selection on a previous screen prefill a field in a form that would be awesome! thank you for reading.

1

1 Answers

1
votes

It sounds like you want to use a collection. A collection can be used similar to a global variable and will allow us to access data on a different screen than the one we set it on.

Some useful information can be found here:
https://powerapps.microsoft.com/en-us/tutorials/working-with-variables/#create-a-collection
https://powerapps.microsoft.com/en-us/tutorials/function-clear-collect-clearcollect/

Based off of your flow, let's assume that the screens are named as follows:

  • Screen1 will be "SpecifyLocation"
  • Screen2 will be "SpecifyAction"
  • Screen3 will be "FinalizeInput"

The names are arbitrary, but I think they'll make the following example easier to follow.

On the screen "SpecifyLocation", we're going to create four buttons. They will all be identical, except for the name of the location they reference. For instance, the button referencing "NY" would be as follows:

  • Text = "New York"
  • OnSelect = ClearCollect( LocationMetadata, "NY" ); Navigate(SpecifyAction,ScreenTransition.Cover)

Please note that the OnSelect value is two different functions separated by a semicolon. The first function, ClearCollect(), clears all information in a collection and then writes a new entry. In this case, we have a collection named LocationMetadata into which we are writing the value "NY". The second function, Navigate(), changes which screen we are looking at.

On the screen "SpecifyAction", we're going to create two buttons. They will be similar, except for the action they refer to. For instance, the button referencing "Add" would be as follows:

  • Text = "Add"
  • OnSelect = ClearCollect( ActionMetadata, "Add" ); Navigate(FinalizeInput,ScreenTransition.Cover)

As was the case before, we've created a button that calls two functions when clicked. They are the same two functions as last time; however, we've changed LocationMetadata to ActionMetadata in our ClearCollect() call, since we want to store a different piece of information. We've also changed our Navigate() call to move us over to the "FinalizeInput" screen.

I'm not entirely sure how you've got your final screen laid out, but in any case, you'll want to access the data we stored in collections previously. This can be done with the function First(), which returns the first element of a collection.

To access our selected location, you can use: First(LocationMetadata).Value
To access our selected action, you can use: First(ActionMetadata).Value

You should be able to supplement whatever extra data is collected from your user on this final screen with the collections we set up.