cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ethan_R
Super User
Super User

Duplicating Records along with its related Records

Hi All,

I'm having a specific requirement where on a button click, need to duplicate that entity's Related record along with its related records.

Basically entity A -> entity B -> entity C.

 

What I have achieved so far,

On click of Record(X) of Entity A, collect data in collection of all related records (Y) in Entity B and another collection of records relating to Record(Y) in entity C.

Now I have duplicated Record(X) in Entity A and related Record(Y) to Entity B.

 

I'm stuck where I need to duplicate Record(Z) from entity C related to new Record(Y) from Entity B.

 

I'm gone through MS Docs. came across With() function which can help but I have no idea how to use. With Function 

I need to perform ForAll() into With.

 

Need Advice.

Thanks 

5 REPLIES 5
EricRegnier
Super User
Super User

Hi @Ethan_R,

You would need to do something like this. Notice the difference in the names EntityA, EntityB and EntityC. EntityAID/EntityBID is the ID of the respective patch results.

With(
  Patch(EntityAs, Defaults(EntityAs), {Column1: "XYZ", Column2: "ABC"}),
  ForAll(EntityBsGallery, 
    With(
      Patch(EntityBs, Defaults(EntityBs), {EntityA: EntityAID, Column1: EntityBGalleryColumn}),
      ForAll(EntityCsGallery, 
        Patch(EntityCs, Defaults(EntityCs), {EntityB: EntityBID, Column1: EntityCGalleryColumn})
      )
    )
  )
)

 Hope this helps!

Hi @EricRegnier ,

I have a problem that column names are same.

How will I know which ID is returned from With function ?

Since its showing alot of errors

 

You don't need to know the ID, that will be known at runtime. The ID is returned from the respective previous Patch.

Since its not allowing...
I've created a collection where I only need to patch Entity B records and related C records to new A.

Here's some info...

Collection consist EntityB and relating EntityC records

 

ForALl(
   collection,
   With(
      Patch(
         EntityB
      ),
      Patch(
         EntityC
      )
   )
)

But it shows errors for 2nd patch.

 

Can't understand what's the issue

Can you share the full error message and the full expression? Thanks!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (1,538)