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

Using ForAll and gallery.AllItems is not iterating through all the items in the Gallery

HI Everyone,

In the form below the user creates a inventory from a template (about 700 records). The record from the template are copied up the to device locally into a collection  Originally, I had the user filling in the numbers using a tablet and posting each record as the user filled in "Qty on Hand". I soon learned this caused time delays on each post and caused it loose focus. This made the user experience very difficult. 

Inventory.JPG

 

To correct this thought I would save all posts to the collection till the user finished the inventory. Then iterate through the gallery and post each value for the inventory count. To do this I thought would first create a test. The test would iterate through all records and assign  "Qty on Hand" a value of 5

Here is my test code:

ForAll(
    Gallery2_11.AllItems,
    Patch(
        TempInvtry,
        LookUp(
            TempInvtry,
            Text(ID) = Title2_11.Text // Gallery ID colomn
        ),
        {Qty: 5} //"Qty on Hand"
    )
);

 

To my surprise it did not iterate through Allitems in gallery. You can see by the above screen shot that it only appeared change random records. If scroll down and press the test button again I get more records changed. 

 

Any Ideas why Allitems is not getting all records?

 

Thanks

8 REPLIES 8
Highlighted
Super User III
Super User III

@JasonF 

As an opening question: if you load your Gallery into a collection does it include all of the items?  Put this code in a random label to check.  Does this number match the rows in your Gallery?

 

CountRows(Gallery2_11.AllItems)

 

The reason I ask is sometimes gallery.allitems does not load all the rows because galleries only retrieve data from the datasource as needed.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Helper III
Helper III

Just to clarify:

CountRows(Gallery2_11.AllItems) seems to work with no problems. Check the bottom right of the screen.

Thanks again,

 

Highlighted

Sorry replied to myself so this will show up twice... sorry for the confusion for future readers.

 

 

Just to clarify:

CountRows(Gallery2_11.AllItems) seems to work with no problems. Check the bottom right of the screen provided. In this example there were 561 records, not 700

Thanks again

Highlighted

@JasonF
Ok, now that we’ve gotten the preliminary question out of the way can you tell me more about your LookUp?

The 2nd argument must compare something in Gallery1.AllItems to something in TempInv. Could you please tell me what is being compared in your function?

LookUp(
    TempInvtry,
    Text(ID) = Title2_11.Text
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

ClearCollect(
    TempInvtry,
    {
        Category1: "",
        ID: 0,
        ItemNO: "",
        UnitQty: 0,
        Descrition: "",
        Qty: 0,
        UnitCost: 0,
        PurchaseCst: 0,
        InRptNo: "",
        UnitType: ""
    }
);
ForAll(
    'Template Details',
    If(
        crdf5_TemplateNo.TemplateNo = TempNo,
        Patch(
            TempInvtry,
            Defaults(TempInvtry),
            {
                Category1: Text(crdf5_Category.Category),
                InRptNo: DataCardValue4_4.Text,
                Qty: 0,
                ID: 'Version Number',
                ItemNO: Text(crdf5_ItemNo.'Item No'),
                UnitCost: crdf5_Units.'Unit Cost Cal',
                Descrition: crdf5_itemdescription,
                PurchaseCst: crdf5_purchasecost,
                UnitType: crdf5_Units.'Unit Type Cal',
                UnitQty: crdf5_UnitQtyCal.'Unit Qty'
            }
        )
    )
)

 

 

 

 

Highlighted
Super User III
Super User III

@JasonF 
I do not necessarily know why the Gallery is not working for you... however, we can try a slightly different approach that does not involve Gallery.AllItems.

My idea is to put this code in the OnChange property of your TextInput_QtyOnHand.  Every time the Qty On Hand is updated by the record-keeper it puts the inventory level changes into a temporary collection called colInvQtyOnHand.

 

 

Set(currentRecord, LookUp(colInvQtyOnHand, ID=ThisItem.ID));
If(IsBlank(currentRecord),
    Patch(colInvQtyOnHand, Defaults(colInvQtyOnHand), {ID: ThisItem.ID, QtyOnHand: ThisItem.TextInput_QtyOnHand.Text}),
    Patch(colInvQtyOnHand, currentRecord, {ID: ThisItem.ID, QtyOnHand: ThisItem.TextInput_QtyOnHand.Text})
) 

 

 

Then when the 'Post Inventory' button gets clicked you could run this code.  Essentially, I'm hoping we can bypass this by removing the any references to the gallery itself.

 

 

ForAll(
    colInvQtyOnHand,
    Patch(
        TempInvtry,
        LookUp(TempInvtry, ID=colInvQtyOnHand[@ID]),
        {Qty: colInvQtyOnHand[@QtyOnHand]}
    )
);

 

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Community Support
Community Support

Hi @JasonF ,

Actually, I agree with @mdevaney .

I could not find where's your problem precisely.

Your formula looks good.

Do you have any delegation warning?

Maybe you could try this:

change the delegation limit to 2000.

delegation.jpg

 This limit will make your app perform not good neither.

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

Thanks for the reply,

I made the change you referenced, with no change in results. I did not expect a change as we are dealing with a collection and my understanding is collections fall outside the delegation problems. Anyway, I am going to try one more test on CDS data sets directly and a gallery and see if the results are the same.

I will keep you posted.

 

Regards.

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 (13,996)