cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
alexesprtu29
Frequent Visitor

How to patch related Dataverse Tables?

Hello, so I have a couple of tables in Dataverse and I'm doing a soft-delete function (just setting a status to inactive).

 

Roles - List of available roles when onboarding.

Documents - List of available documents when onboarding.

RoleDocuments - Mapping of roles to documents (both just lookup columns)

 

Role

Role 1

Role 2

Role 3

Role 4

 

Documents

Doc 1 

Doc 2 

Doc 3 

 

RoleDocuments

Role 1 - Doc 2

Role 1 - Doc 4 

Role 2 - Doc 1

Role 2 - Doc 2

 

I was already able to do the patching for direct deletes (deleting an item in the documents/roles table).


However I am having some trouble with deleting the associated roles/documents in the RoleDocuments table when I am deleting a Role/Document. Not sure if I'm making sense but if I delete Doc2 then the mapping of all roles with doc2 on them should be inactive as well.

 

ForAll(
    Filter(
        RoleDocuments,
        DocID.'Document Name'= ThisItem.'Document Name'
    ) As _item,
    Patch(
        RoleDocuments,
        LookUp(
            RoleDocuments,
            DocID.DocID = ThisItem.DocID
        ),
        {cr2d9_roledocumentstatus: 'Role Document Status (RoleDocuments)'.No}
    )
);

This is the first thing I tried but it says that the function cannot operate on the same datasource. I did see on another answer that I can just rename the ID column differently to make it work so it did, however it only updates one row in the RoleDocuments column. Any help would be appreciated! 

2 REPLIES 2
AhmedSalih
Super User
Super User

Hello, @alexesprtu29, another easier way to do this is using a collection, UpdateIF, and Patch:

ClearCollect(colRoleDocuments,
Filter(
        RoleDocuments,
        DocID.'Document Name'= ThisItem.'Document Name'
    ) 
);
UpdateIf(colRoleDocuments,true, 
{cr2d9_roledocumentstatus: 'Role Document Status (RoleDocuments)'.No}
);
    Patch(
        RoleDocuments,
        colRoleDocuments
);

 

 

Regards,
Ahmed
If my reply helped you, please give a 👍. And if it has solved your issue, please consider Accepting it as the Solution to help other members of the community find it more.

 

AhmedSalih
Super User
Super User

Hello

Regards,
Ahmed
If my reply helped you, please give a 👍. And if it has solved your issue, please consider a 👍 & Accepting it as the Solution to help other members of the community find it more.

@alexesprtu29, I wanted to check and see if my recommended approach worked for?

 

 

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 (6,502)