Hi all
New to PowerApps, I have built a handover form for my team mates in PowerApps that works well but I would like to streamline it a bit.
At the moment they submit the form and start a new blank form, I would like to copy information from the last saved form to pre-populate different text fields in the new form.
This will save them from having to copy and paste the data across.
On submit the data is saved into a SharePoint list.
I have tried reseting card values but on submit it just overwrites the SharePoint entry with new card values and does not start a new entry.
Is this possible?
If so any information would be great.
Thanks in advance
Solved! Go to Solution.
No, Patch is a function that patches records. If you specify a datasource for patch, then it knows to interact with a datasource. Otherwise, it patches records.
So in #3:
First, we get the record that we want with the Coalesce function. This will return the first record that is not blank.
So the first time, glbCurrentRecord will be blank and thus this will return the Defaults record for the datasource. (if there are no default values for the list, that can actually all be removed)
Second, we take that record from the Coalesce and patch it with another record. The other record is just simply {ID: Blank()}
This will essentially just blank out the ID column.
When you submit the form, if the ID is blank, then it knows to create the record. If it has a value, then it knows to update that record (same thing Patch does when working with a datasource by the way!)
So, by doing the patch, we are taking (after the first submit) the record that was last submitted, which will have ALL of the values submitted, and then we blank out the ID. This way, the form now has all the values from the previous submit, but since we just blanked out the ID, when it is submitted, it will be a new record that is created.
Hopefully that is pretty clear to understand. But, a takeaway, Patch is a multi-use function and is very powerful in PowerApps for modifying data in the app and even reshaping it.
Hi @RandyHayes
I'm working with the #3 formula and the round brackets are not equal, so I changed it to this:
Patch(Coalesce(SelectedAsset,Defaults(Assets),{AssetRecID:Blank()}))
but I'm getting an error, received one argument, expecting 2 or more.
I'm playing with it but not having any success.
Yes, there was a missing paren in the original...I will correct it.
Yours has the closing paren in the wrong place. The closing paren to close the Coalesce function was missing...yours should be:
Patch(Coalesce(SelectedAsset,Defaults(Assets)),{AssetRecID:Blank()})
Also, is AssetRecID your primary key on your list? It is always the primary key that needs to be "blanked" out.
Hi @RandyHayes
I'm getting an error with your updated formula...
Assets is a Dataverse table. AssetRecID is an autonumber field in the table, the field "Assets" shows as the Data type = Unique Identifier.
I have a screen that shows all my Assets in a Gallery. When the user clicks on a record, it sets the variable SelectedAsset equal to ThisItem and takes the user to the form screen. The form is in View mode. The user can change it to Edit mode. On the asset listing screen there is also a "+" button that takes them to the form screen but makes the form "New" instead of "Edit", which makes an empty form.
I then have 2 buttons and a toggle.
The Toggle lets the user decide if they want to save and make a copy of the data they're saving (what I'm trying to solve now)
A Save button that only saves the current record and then changes the form to "View"
A third button that saves the record and then is supposed to make a new record (empty or with the just saved record... depending on the toggle)
So on the forms OnSuccess I've added:
Set(SelectedAsset,ViewEditAssetForm.LastSubmit);
Sorry to add the complexity... just trying to provide all info to try and solve the formula error in the Items property of the form.
Thanks 🙂
So the Asset column is your primary key to the table. That is the one you want to blank out.
Your Items property should be:
Patch(Coalesce(SelectedAsset,Defaults(Assets)),{Asset: Blank()})
However, since you are introducing a toggle, this might be better moved to the OnSuccess.
So, your Item property on the Form would be: SelectedAsset
And the OnSuccess formula would be:
Set(SelectedAsset,
If(yourToggle.Value,
Patch(Self.LastSubmit, {Asset:Blank()}),
Defaults(Assets)
)
)
Hi @RandyHayes
I've implemented your code but for some reason the Asset:Blank() is not occurring
Set(
SelectedAsset,
If(
EmptyFormAfterSave.Value = false,
Patch(
Self.LastSubmit,
{Assets: Blank()}
),
Defaults(Assets)
)
)
I flipped the logic so that if the toggle is false, then the form is not cleared, which means that the users wants to keep the record as a duplicate and edit it to make a new record and save.
The form clears when the toggle is true.
Can't seem to sort it out.
Update: Does it matter is SelectedAssets is a variable vs. a Collection?
Update: I made a button with this formula in the OnSelect and when I did that, I got an error on the Items property
Set(SelectedAsset,Patch(SelectedAsset,{Assets:Blank(),AssetRecID:Blank()}))
The error is: Invalid formula. Expected a value compatible with 'DataSource'.
If I delete the button, the error goes away. I tried taking out the AssetRecID part and that makes no difference.
I made the button just to see if I could clear those values from the variable (I now know you can do this) and it seems I can't.
So first - we need to identify the primary key of your table. I am going to assume it is Assets. But, to be sure, go to the settings for your table and see what it shows for the Primary Key.
I was mistaken on the formula! I always forget that it needs the real name of the column.
So, the formula should be:
Set(
SelectedAsset,
If(
!EmptyFormAfterSave.Value,
Patch(
Self.LastSubmit,
{cra98_assetsid: Blank()}
),
Defaults(Assets)
)
)
Hi @RandyHayes
Thank you so much for sticking with me on this one.
I looked at the Settings and it refers to the Region column... so I took a screen shot of that and the other columns here...
I also thought of using the "cra" name, but when I typed it in, it did not come up, but when I type Assets, it comes up as "Assets:" so I assumed that was correct.
Should I be setting Region as blank even though cra98_assetsid is the unique identifier?
Thanks
No problem!
Yes, if that is the primary key, then that is what you want to blank. So...
Set(
SelectedAsset,
If(
!EmptyFormAfterSave.Value,
Patch(
Self.LastSubmit,
{cra98_region: Blank()}
),
Defaults(Assets)
)
)
Hi @RandyHayes
I will update my code to that, but am a bit confused.
Isn't a primary key supposed to be unique values? The data in this column will be either East, West or Central.
Thanks
User | Count |
---|---|
253 | |
106 | |
94 | |
50 | |
39 |