cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ArthurLin
Level: Powered On

using existing record to create

Hihi,

I am junior for using powerapps. I have below question and hope to get help

 

the record is already in the database. however, I would like to edit this record and then save as a new transaction. How can i do that? Please kindly help

4 REPLIES 4
Dual Super User
Dual Super User

Re: using existing record to create

Hi @ArthurLin 

 

If I understood this correctly, you want to create a new record by using the values from an existing one.
 
For this, you can create an Edit Form, select the data source, and set the "Item" property to point to specific record using expression:
 
LookUp(DataSourceName, Title = "Test")
This will get the first record matching the criteria.
 
Now, you can create a button to save this record to datasource.
 
Button -> OnSelect -> Patch(DataSourceName,Defaults(DataSourceName),{Title:DataCardValue2.Text,Choice: DataCardValue5.Selected.Value})
 
Here, DataSourceName is the name of data source. Title and Choice are the name of columns, while DataCardValue2/DataCardValue5 refers to the name of controls.
 
 
In you need specifics for the formula, please share more details about the logical implementation.

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Highlighted
SaWu
Level 8

Re: using existing record to create

Hi @ArthurLin 

As @yashag2255 already pointed out, you can use Patch to create copies of records, using Defaults for the BaseRecord argument of Patch.
You can also use your original record (that you want to copy) as ChangeRecord.
This might be easier than explicitly listing every control in the form, and making sure the form has all necessary controls, in order to get a full-enough copy.

If you use your original record in this way as ChangeRecord, you might have to drop the read-only columns (only for the use in Patch as ChangeRecord) which get set automatically by the Database/Dynamics/CDS (e.g. guid fields, createdby, createdon...).
Otherwise PowerApps (i.e. the CDS connector) might yield an error on your actual attempts to use Patch.
Those kinds of errors won't appear in the App Checker before actual execution.

With CDS/Dynamics, you can also replace Defaults with a record containing only a Blank() guid field to force the creation of a new record instead of overwriting an old one.
image.png
Here's a more explicit version of what I'm trying to convey:

Patch([@DataSource],
    {
        GuidField: Blank()
    },
    originalRecord
)


Good luck,
    Sa.

Community Support Team
Community Support Team

Re: using existing record to create

Hi @ArthurLin ,

How do you edit existing record of your data source within your app? Using Edit form?

 

I assume that you use Edit form to edit an existing record in your data source within your app, based on the needs that you mentioned, I think the Patch function could achieve your needs.

 

I have made a test on my side, please take a try with the following workaround:

Within your Edit screen (which contains Edit form), add a Button called "Existing to New", set the OnSelect property to following:

Patch(
          'YourDataSource',
           Defaults('YourDataSource'),
           EditForm1.Updates               /* <-- EditForm1 represents the Edit form in your app to edit the existing record */
)

Please take a try with above solution, check if the issue is solved.

After you edit your existing record within the Edit form, click the "Existing to New" button, then it would save the modified existing record into your data source as New record.

 

In addition, you could also consider set the OnSelect proeprty of the "Submit" button within your Edit form to following:

Patch(                    /* <-- Add this formula */
          'YourDataSource',
           Defaults('YourDataSource'),
           EditForm1.Updates               /* <-- EditForm1 represents the Edit form in your app to edit the existing record */
);
SubmitForm(EditForm1)

When you press the Submit button, it would update existing record in your data source, and create a new record using the modified existing record at the same time.

 

More details about the Patch function, please check the following article:

Patch function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
SaWu
Level 8

Re: using existing record to create

Hello @v-xida-msft 

Does using Form.Updates actually work for creating proper copies?
I was under the impression that Form.Updates only produced something like a "diff" record with changes.
So, as far as I understand, this won't be creating a full copy unless you have every field in the form and actually change every field.
Please, do let me know whether my understanding is wrong.

Thank you,
    Sa.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,059)