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

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
Resolver II
Resolver II

Re: Copying all records in CollectionA to corresponding record in CollectionB

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
Super User

Re: Copying all records in CollectionA to corresponding record in CollectionB

@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.
Highlighted
Resolver II
Resolver II

Re: Copying all records in CollectionA to corresponding record in CollectionB

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
Super User
Super User

Re: Copying all records in CollectionA to corresponding record in CollectionB

@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.
Highlighted
Resolver II
Resolver II

Re: Copying all records in CollectionA to corresponding record in CollectionB

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

Highlighted
Super User
Super User

Re: Copying all records in CollectionA to corresponding record in CollectionB

@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.
Highlighted
Resolver II
Resolver II

Re: Copying all records in CollectionA to corresponding record in CollectionB

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
Resolver II
Resolver II

Re: Copying all records in CollectionA to corresponding record in CollectionB

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
Super User
Super User

Re: Copying all records in CollectionA to corresponding record in CollectionB

@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.

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,215)