I added a timer feature to my app and I want to have a button available that when pressed, will copy the timer data and input it into a datacard of my choosing. When the "Record Pour" button is selected, I'd like the timer data to be copied into the "Pour Time" field. Is this possible?
In Powerapps, in order to change the value of a property at run time, you need to use variables. From my understanding a "Datacard" is a generic group of objects in a form, so I will assume for this problem, the object you want to set as the time is a label object.
1. Set the text property of the label to be your variable.
2. In the buttons onClick property, you then need to set the variables value to the current time:
Hope this helps.
I don't think that works quite right. Since this is a sharepoint list, theres several items within the list and they all have several inputs, including this pour time input. If I change that datacard field to a variable (lets call it RecordPour) and then change the button to set that variable, it changes the data for every item that I open in that screen. For example, if I open one item and set the time to 1 second, it will change that field. However, if I save that item and open another, that second item will also have the field set to 1 second. I hope that makes sense.
I agree with @samuelJ's thought almost. I think the global variable could achieve your needs.
Based on the issue that you mentioned about the variable, I think you should clear/reset the global variable when you open a new item every time.
I have made a test on my side, please take a try with the following workaround:
Set the OnVisible property of the Edit/New screen which contains the form to following:
Set the Default property of the Text Input box within the Pour Time Data card to following:
Set the OnSelect property of the "Record Pour" button to following:
Set(TimerValue, Timer1.Text) /* <- Timer1 represents the Timer control within your app */
That's a little closer to what I was hoping to do. However, it does blank the value out so if you want to edit an item and not touch that field (which we will assume is already populated in this scenario), it will be erased. Is there any way around that?
I am not quite understanding the issue. Based on the original post, my understanding is that there was a form with ONE field we wanted populated with a timer value. My assumption was also that these values were populating a form, which would then be updated in a database later, as the value will not be retained through app sessions. If these assumptions are wrong, the above solution is not correct. So, the real problem to solve is you want to populate multiple values with different times, essentially like the "Lap" feature on a timer
If you have X objects you want to set to the current time when pushing a button, you need X variables. You then need a way to determine what variable the current lap should be assigned to. There are a few ways to do this.
1. Have multiple buttons, that each set a different variables times, this is propably the easiest solution but not most elegant if you have many fields.
2. Have some way to determine which variable it is you want to set. You could do this with the OnSelect property of the object you want to set. You would need another global variables that changes when selecting the desired object:
Then in the code I suggested before you would need to determine which variable you are using.
If(currentTimeSelection = 1, Set(myVariableName1, myTimer.Text), If(currentTimeSelection = 2, Set(myVariableName2, myTimer.Text, //etc code for each variable needed)))
There are other ways to implement this, it comes down to what you want to implement. If none of these sound right, perhaps provide more insight into what your app looks like and how exactly you want the flow of your app, how is it intended to be used.
Your original assumption was correct, there is one field that we want populated with a timer value. @v-xida-msft's solution was closer to what I was trying to achieve, but created another problem that needs to be tackled. Here's the scenario:
1) The edit form is opened and a blank field needs to be populated with a timer value
2) The timer value populates the field with the button that we added earlier
3) The form is now saved.
4) The form is opened again for editing a different field
5) The field that we populated with a timer value is now blanked out due to the OnVisible formula added above (Set(TimerValue, Blank()).
I tried changing the OnVisible formula to OnSelect for the data field I'm editing, which solved that issue but created a new one. If the app is opened and the form is edited, it appears to default that variable to blank, but if I tried to edit a form, save, and then edit another form without closing the app, the original saved data still shows). So it seems like this variable defaults to blank when the app is opened. Any ideas?
Appreciate all the help so far!
Fill out a quick form to claim your user group badge now!
Find out where you can attend!
Features releasing from October 2019 through March 2020
Learn how to build the business apps that you need.