cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Microsoft
Microsoft

Copying all records in CollectionA to corresponding record in CollectionB

I'm copying all the contents of the GroupItems collection onto the same ID in the PSOCache collection. Both collections have the same set of columns. Patch does not work because of the empty fields bug. I'm looking for a succinct way to make this work.

ForAll(
    RenameColumns(GroupItems
        , "ID"
        , "ContentID"
    ),
    UpdateIf(
        PSOCache
        , ID=ContentID
        , {
            Status: Status
            , StatusText: StatusText
            , 'Status Detail': 'Status Detail'
            , Inspected: Inspected
            , MSF: MSF
            , SN: SN
            , Ticket: Ticket
            , 'Vendor Part Number': 'Vendor Part Number'
            , Description: Description
            , Bin: Bin
            , Edited: Edited
        }
    )

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Your suggestion won't *quite* work because there is no record scope for GroupItems. The record scope within ForAll is 

    RenameColumns(GroupItems
        , "ID"
        , "ContentID"
    )

The documentation says, "If the table being operated upon is an expression, such as Filter( Table, ... ), then the disambiguation operator cannot be used. Only the innermost record scope can access fields from this table expression, by not using the disambiguation operator." although I'm not quite sure what that last sentence means. 

 

But you did give me an idea. This seems to work:  

ForAll(
    GroupItems,
    UpdateIf(
        PSOCache,
        ID=GroupItems[@ID],
        {
            Status: GroupItems[@Status]
            , StatusText: GroupItems[@StatusText]
            , 'Status Detail': GroupItems[@'Status Detail']
            , Inspected: GroupItems[@Inspected]
            , MSF: GroupItems[@MSF]
            , SN: GroupItems[@SN]
            , Ticket: GroupItems[@Ticket]
            , 'Vendor Part Number': GroupItems[@'Vendor Part Number']
            , Description: GroupItems[@Description]
            , Bin: GroupItems[@Bin]
            , Edited: GroupItems[@Edited]
        }
    )
);
Back()

Thanks!

View solution in original post

8 REPLIES 8
Highlighted
Super User III
Super User III

@sopatte 

So, you mentioned Patch as an issue, but your formula is using UpdateIf.  Are you having a particular issue with that formula?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!
Highlighted

I'm working around the Patch issue.

 

Yes. I believe there's a scoping issue in my formula. I want to update each record in PSOCache with the contents of the corresponding record in GroupItems.

 

Also tried:

UpdateIf(
    PSOCache,
    true,
    Lookup(GroupItems,ID=PSOCache[@ID])
)

 

 

Highlighted

@sopatte 

At a glance...your initial formula you posted should have worked.  What issues are you finding with it?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!
Highlighted

I believe within the record being passed as the third argument to UpdateIf, the values are scoped to PSOCache.

Highlighted

@sopatte 

That may or may not be the case.  I find that PowerApps is usually smart enough to work this out without an issue.  Sometimes..at least 😉 

So, my question would be - have you tried that formula and have you noticed an issue with it that would lead you to a scoping issue?

If so, then perhaps change your individual assignments to statements similar to this:

 {  Status: GroupItems[@Status]
  , StatusText: GroupItems[@StatusText]
  , etc....

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!
Highlighted

Your suggestion won't *quite* work because there is no record scope for GroupItems. The record scope within ForAll is 

    RenameColumns(GroupItems
        , "ID"
        , "ContentID"
    )

The documentation says, "If the table being operated upon is an expression, such as Filter( Table, ... ), then the disambiguation operator cannot be used. Only the innermost record scope can access fields from this table expression, by not using the disambiguation operator." although I'm not quite sure what that last sentence means. 

 

But you did give me an idea. This seems to work:  

ForAll(
    GroupItems,
    UpdateIf(
        PSOCache,
        ID=GroupItems[@ID],
        {
            Status: GroupItems[@Status]
            , StatusText: GroupItems[@StatusText]
            , 'Status Detail': GroupItems[@'Status Detail']
            , Inspected: GroupItems[@Inspected]
            , MSF: GroupItems[@MSF]
            , SN: GroupItems[@SN]
            , Ticket: GroupItems[@Ticket]
            , 'Vendor Part Number': GroupItems[@'Vendor Part Number']
            , Description: GroupItems[@Description]
            , Bin: GroupItems[@Bin]
            , Edited: GroupItems[@Edited]
        }
    )
);
Back()

Thanks!

View solution in original post

Highlighted

I've suggested this feature before but how great would it be if in any record scope ThisItem was defined to refer to the entire record?

ForAll(
    GroupItems,
    UpdateIf(
        PSOCache,
        ID=GroupItems[@ID],
        GroupItems[@ThisItem]
    )
)

 

Highlighted

@sopatte 

Agreed.

You can get close though with this type of construct:

 

ForAll(GroupBy(RenameColumns(GroupItems, "ID", "colAID"), "colAID", "ThisItemA"),
UpdateIf(PSOCache, ID=colAID, 
{
            Status: First(ThisItemA).Status
            , StatusText: First(ThisItemA).StatusText
         
etc...

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,177)