cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SaWu Impactful Individual
Impactful Individual

How do you trigger Gallery.Items recomputation?

Hello

Please be so kind as to read my full post before responding.
Thank you for your consideration.

In one PowerApp I have built something akin to a multi-select picklist using two Galleries.
image.png
The purpose is to assign Orders to Delivieres.
Orders are collected locally into LocalOrders upon App.OnStart or RefreshButton.OnSelect.

To upper Gallery (containing the Orders assigned to the current delivery) has Items

Filter(LocalOrders, !IsBlank(kk_warehouse_delivery_id), kk_warehouse_delivery_id.kk_warehouse_deliveryid=selectedDelivery.kk_warehouse_deliveryid)

and, inside the template, UnassignButton.OnSelect

Unrelate(LookUp([@'Auslieferungen (WA)'], kk_warehouse_deliveryid=selectedDelivery.kk_warehouse_deliveryid).'Aufträge (WA)', LookUp([@'Aufträge (WA)'], kk_warehouse_orderid=ThisItem.kk_warehouse_orderid));
Patch(LocalOrders, {kk_warehouse_orderid: ThisItem.kk_warehouse_orderid}, {
    kk_warehouse_delivery_id: Blank()
});

as formulae of the Trash icon.
The lower Gallery (containing the unassigned Orders) has Items

Filter(LocalAuftraege, IsBlank(kk_warehouse_delivery_id))

and, inside the template, AssignButton.OnSelect

Relate(LookUp([@'Auslieferungen (WA)'], kk_warehouse_deliveryid=selectedDelivery.kk_warehouse_deliveryid).'Aufträge (WA)', LookUp([@'Aufträge (WA)'], kk_warehouse_orderid=ThisItem.kk_warehouse_orderid));
Patch(LocalAuftraege, {kk_warehouse_orderid: ThisItem.kk_warehouse_orderid}, {
    kk_warehouse_delivery_id: selectedDelivery
});

as formula of the + Icon
Relate/Unrelate takes care of the LookUp fields/Relational Data table on the CRM side.
On the local side I use Patch.

The UnassignButton does everything I expect it to do, setting the lookup field to Blank in the CRM and in my local collection.
Also both galleries seem to always refresh Items whenever I use this UnassignButton.

However, the AssignButton appears to sometimes work, and sometimes do nothing.
A closer look tells me that on the data level setting the CRM and in my local collection both work properly.
But, the galleries don't update and still show me (wrong) Items in both galleries.
It appears as if the recomputation of both gallery Items isn't triggered upon setting the relevant lookup fields in my local collection LocalOrders.
Exiting the screen and reloading the delivery properly refreshes both galleries, which then show the previously reassigned orders in the correct galleries.

My questions:

  1. Can I manually trigger the recomputation of Gallery.Items?
  2. Why does my UnassignButton and setting the lookup field to Blank apparently trigger a recomputation of Gallery.Items while setting to a nonblank value does not?

Last test with:

App ID: 8200a3f3-30fd-44f9-b3b7-0c9e0f803c50
Session ID: 21a66c2e-a2f6-472c-bffc-a84600ce0745
PowerApps 3.19081.26

Thank you,
    Sa.

3 REPLIES 3
SaWu Impactful Individual
Impactful Individual

Re: How do you trigger Gallery.Items recomputation?

Hello

I have an inefficient workaround using ClearCollect but this still doesn't really answer my questions.

Thanks,
    Sa.

Lisabel0 Helper V
Helper V

Re: How do you trigger Gallery.Items recomputation?

Can you share your workaround?

Highlighted
SaWu Impactful Individual
Impactful Individual

Re: How do you trigger Gallery.Items recomputation?

Hi @Lisabel0

My workaround, obviously copy & pasted using the names etc of my own DataSources and entities etc:

  1. Add an invisible (dummy) button LieferungCollect to the Screen, with OnSelect set to
    Refresh([@'Aufträge (WA)']);
    Concurrent(
        If(!IsBlank(selectedDelivery.kk_warehouse_deliveryid), 
            ClearCollect(LocalAssigned, Filter([@'Aufträge (WA)'], kk_warehouse_delivery_id.kk_warehouse_deliveryid=selectedDelivery.kk_warehouse_deliveryid)),
            Clear(LocalAssigned)
        ),
        ClearCollect(LocalUnassigned, Filter([@'Aufträge (WA)'], IsBlank(kk_warehouse_delivery_id)))
    )
  2. Change the Items of the AssignedGallery of assigned items/orders to
    LocalAssigned
  3. Change the Items of the UnassignedGallery of unassigned items/orders to
    LocalUnassigned
  4. Add Select(LieferungCollect) in all relevant control events, i.e.
    Screen.OnVisible:
    Select(LieferungCollect);
    AssignButton.OnSelect in the UnassignedGallery Template:
    Relate(LookUp([@'Auslieferungen (WA)'], kk_warehouse_deliveryid=selectedDelivery.kk_warehouse_deliveryid).'Aufträge (WA)', LookUp([@'Aufträge (WA)'], kk_warehouse_orderid=itemId));
    Select(LieferungCollect);
    UnassignButton.OnSelect in the AssignedGallery Template:
    Unrelate(LookUp([@'Auslieferungen (WA)'], kk_warehouse_deliveryid=selectedDelivery.kk_warehouse_deliveryid).'Aufträge (WA)', LookUp([@'Aufträge (WA)'], kk_warehouse_orderid=itemId));
    Select(LieferungCollect);

Essentially I use local Collections for the Items of both galleries and re-collect these collections upon loading and after every change to the relational data.


I hope this helps a bit.
Good luck,
    Sa.

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

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