web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Copying data from one ...
Power Apps
Suggested Answer

Copying data from one dataverse table to another

(0) ShareShare
ReportReport
Posted on by
I am trying to upsert data from one table to another depending if record is already copied or not (so if record already exists then update orthervise insert). I got this from copilot and i understand it but having trouble in getting it to work
ForAll(
    Search(sourceTbl, txtFindValue.Text, 'Value To Find'),
    With(
        {
            inboundRecord: LookUp(destinationTbl, keyCol = ThisRecord.keyCol)
        },
        If(
            Not(IsBlank(inboundRecord)),
            Patch(
                'destinationTbl',
                inboundRecord,
                {
                    col1: ThisRecord.col1,
                    col2: ThisRecord.col2
                }
            ),
            Patch(
                destinationTbl,
                Defaults(destinationTbl),
                {
                    keyCol: ThisRecord.keyCol,
                    col1: ThisRecord.col1,
                    col2: ThisRecord.col2
                }
            )
        );
        Notify("Processed record: " & ThisRecord.keyCol, NotificationType.Success)
    )
)
 
if ill change ThisRecord.X to hardcorded strings (like "I am a value") and try to use this then it works but for some reason ThisRecord-object exists in the first lookup but it cannot be accessed inside patch-function. Then again inboundRecord-object I able able access inside path function but then I am again not able to do the insert with a new record. 
 
Would you be able to help me?
I have the same question (0)
  • CU31121026-0 Profile Picture
    4 on at
    Then I have also tried a shorter one where row updates work ok but not insert
    ForAll(
        Filter(SourceTable, SearchColumn = txtSearch.Text),
        Patch(
            DestinationTable,
            LookUp(DestinationTable, KeyColumn = ThisRecord.KeyColumn),
            {
                FieldToUpdate1: ThisRecord.FieldToCopy1,
                FieldToUpdate2: ThisRecord.FieldToCopy2,
            },
            Defaults(DestinationTable),
    		{
    			keyfieldToInsert: ThisRecord.KeyColumn
                FieldToInsert1: ThisRecord.FieldToCopy1,
                FieldToInsert2: ThisRecord.FieldToCopy2,
            }
        )
    )
     
  • Suggested answer
    CU31121026-0 Profile Picture
    4 on at
    Ok... So I have a feeling that I might have resolved this one by my self. Seems than with the first code lookup-function didnt update inboundRecords-variable to blank but somehow held previous iteration value!!! I really dont understand this!!!

    Did it now like this:
    ForAll(
        Search(sourceTbl, txtFindValue.Text, 'Value To Find'),
        With(
            {
                inboundRecords: Search(destinationTbl, ThisRecord.keyCol, keyCol)
    			outboundRecord: ThisRecord
            },
            If(
                Not(IsEmpty(inboundRecords)),
                Patch(
                    destinationTbl,
                    LookUp(destinationTbl, keyCol = ThisRecord.keyCol),
                    {
                        col1: outboundRecord.col1,
                        col2: outboundRecord.col2
                    }
                ),
                Patch(
                    destinationTbl,
                    Defaults(destinationTbl),
                    {
                        keyCol: ThisRecord.keyCol,
                        col1: outboundRecord.col1,
                        col2: outboundRecord.col2
                    }
                )
            );
        )
    )
    with IsEmpty I am not inspecting if records populated with Search function

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 386 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 361

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 339 Super User 2025 Season 2

Last 30 days Overall leaderboard