cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MH5
Helper I
Helper I

Submit a defined number of copies of a form into SharePoint list

I'm trying to find a way to patch specific data into a SharePoint list to be able to start a workflow.

I have an app that is being used on MS Teams

 

The App currently has a detailed form which submits to a SharePoint list (Container arrivals), this part of the app is working fine.

To avoid data duplication and a lot of manual work, I would want to connect the data input of this form with additional data which needs to populate another list (Outgoing Trucks) but I also need to then connect both these data inputs to start another workflow in yet another SharePoint list (Picking Orders).

 

To be able to do this the app has a gallery which provides similar functionality to a repeating table (InfoPath), the data from this gallery and some of the data of the form is patched into a collection (Containers). This collection goes into (Picking Orders) using patch upon onsuccess of the form.

 

MH5_2-1662993192964.png

 

What I haven't been able to figure out yet is how to get the app to create as many items into SharePoint as indicated by the quantity field. 

So if the above has x containers scheduled to arrive, at a certain destination, it needs to populate x amount of new items into the SharePoint list with information coming both from the gallery as well as the form.

 

I was able to achieve the same outcome by using power automate by using 'loop count' and 'do until', but this flow will get stuck at times and it is not feasible to monitor these flows individually going forward.

I have the 'item lines' collected in a collection within the app with the form and gallery data combined, but I haven't been able to figure out how to patch the 'line item' into SharePoint for 'Quantity' amount of times.

 

'OnSuccess' property of the form

 

 

ForAll(
    Containers,
    If(
        !IsBlank(Destination),
        Patch(
            'Picking Orders',
            Defaults('Picking Orders'),
            {
                Destination: Destination,
                'Customer Order Number': CON,
                'Part Type': Part,
                Quantity: Qty,
                'Order ID': OrderForm.LastSubmit.ID,
		Title: OrderForm.LastSubmit.'SO',
		'Loading Dock': OrderForm.LastSubmit.'Dock',
		'Container Type': OrderForm.LastSubmit.'Mix or Bulk',
		Hazard: OrderForm.LastSubmit.'Hazard',
		'Customer Name': OrderForm.LastSubmit.'Cust Name',
		Address: OrderForm.LastSubmit.'Address concat'
            }
        )
    )
)

 

 

On the save button in the gallery

 

 

Patch(
    Containers,
    ThisItem,
    {
        CON: Custorder.Value,
        Part: TextInput2.Text,
        Destination: ComboBox1.Selected.Name,
        Qty: Value(inputQty.Text),
        ShowSaveButtons: false
    }
);
If(
    EditPressed,
    false,
    Collect(
       Containers,
        {
            Destination: "",
            Part: "",
            Qty: 0,
            CON: "",
            ShowSaveButtons: true
        }
    )
);
UpdateContext({EditPressed: false});
Set(
    NeedsSaved,
    false
)

 

 

 

Any ideas on how to achieve that without using automate? Anyone have something that achieves the same outcome with minimal failures?

4 REPLIES 4
RandyHayes
Super User
Super User

@MH5 

To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance.

 

So your OnSuccess action should be the following:

With({_f: Self.LastSubmit},
    Patch('Picking Orders',
        ForAll(Filter(Containers, !IsBlank(Destination)),
            {
             Destination: Destination,
             'Customer Order Number': CON,
             'Part Type': Part,
             Quantity: Qty,
             'Order ID': _f.ID,
             Title: _f.'SO',
             'Loading Dock': _f.'Dock',
             'Container Type': _f.'Mix or Bulk',
             Hazard: _f.'Hazard',
             'Customer Name': _f.'Cust Name',
             Address: _f.'Address concat'
             }
        )
    )
)

 

Now, that said, you really don't need to mess with a collection as you already have your data in your gallery.

You need a base collection simply to allow adding rows to your gallery, but beyond that, there is no need to waste time on duplicating the data from the gallery to the collection.

 

But more specific to your design - are you stating that upon form submit, you want the Picking Orders list to contain one record for each item in the gallery multiplied by the Qty in the gallery?  Or am I missing something?

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
MH5
Helper I
Helper I


@RandyHayes 

But more specific to your design - are you stating that upon form submit, you want the Picking Orders list to contain one record for each item in the gallery multiplied by the Qty in the gallery?  Or am I missing something?


Correct, this data would go into a SharePoint list where our staff gets a task assigned and a link to the new item. They would go to the identified location and collect additional information about the container which goes into this same SharePoint list. With the additional information the picking lists will be generated once the product is called off. The process is already operational, but at certain steps there are issues or gaps. The purpose of this app is to improve and replace a few of these steps.

 

Currently we would have people create new items manually into the containers list, then using power automate, there is a flow that upon creation of a new item in the containers list would create as many new items as the quantity specifies. So lets say that we received a mixed container with bananas and mangos, the bananas had 3 variants and the mangos had 5, within picking orders we would need 3 items for the bananas and 5 for the mangos so that their variants could be recorded with their item quantities and additional information. But we would find that the flow is triggered but needs to be restarted or triggered again due to failure.

 

I'm using the collections because I'm new to Power Apps and I wanted to see some of the data visualized as I build various parts. The collection here itself is cleared at the end of each workflow and I think I may be using it here and there because I'm trying to work around lookup columns in SharePoint, I haven't quite figured out how to work with that record type yet. In my mind, I'm trying to get the collection to show the result I would eventually like to see in the SharePoint list before I connect the final list up as that one is already in production with live data.

 

I'm looking at the with function you've used above (didn't know about it) but I don't understand how _f is being used, the way I am currently reading it _f references self.lastsubmit, does self reference the same form the function is called on, and does _f then mean that _f used within that formula references formname.lastsubmit?

Using your suggested changes, I'm currently trying to make the following work in the "OnSuccess" property.

 

With({_f: Self.LastSubmit},
IF(_f.'Container Type'="Mix" ,
 Patch('Picking Orders',
        ForAll(Filter(Containers, !IsBlank(Destination)),
            <<patch the below * Quantity>>
          {
             Destination: Destination,
             'Customer Order Number': CON,
             'Part Type': Part,
             Quantity: 1,
             'Order ID': _f.ID,
             Title: _f.'SO',
             'Loading Dock': _f.'Dock',
             'Container Type': _f.'Mix or Bulk',
             Hazard: _f.'Hazard',
             'Customer Name': _f.'Cust Name',
             Address: _f.'Address concat'
             }
 ))),
Patch('Picking Orders',
        ForAll(Filter(Containers, !IsBlank(Destination)),
            {
             Destination: Destination,
             'Customer Order Number': CON,
             'Part Type': Part,
             Quantity: Qty,
             'Order ID': _f.ID,
             Title: _f.'SO',
             'Loading Dock': _f.'Dock',
             'Container Type': _f.'Mix or Bulk',
             Hazard: _f.'Hazard',
             'Customer Name': _f.'Cust Name',
             Address: _f.'Address concat'
             }
)))
)

 for the << patch the below * QTY>>, that's the part of the formula I'm looking to solve. I was looking into the sequence function (sequence(Quantity), but I am struggling to make that fit and all I'm getting is angry squiggly lines throughout.

You'll notice that an IF function snuck in, that's because the item only needs to be duplicated into the list if the container is identified as a mixed type. (bulk containers would only have 1 variant of the product)

MH5
Helper I
Helper I

Trying to achieve the patch*Qty part with the OnSuccess property below:

 

ForAll(
    Filter(
        Containers,
        !IsBlank(Destination)
    ),
    ForAll(
        Sequence(inputQty / Label1),
        Patch(
            'Picking Orders',
            Defaults('Picking Orders'),
            {
             Destination: Destination,
             'Customer Order Number': CON,
             'Part Type': Part,
             Quantity: Label1,
             'Order ID': _f.ID,
             Title: _f.'SO',
             'Loading Dock': _f.'Dock',
             'Container Type': _f.'Mix or Bulk',
             Hazard: _f.'Hazard',
             'Customer Name': _f.'Cust Name',
             Address: _f.'Address concat'
             }
        )
    )
)

 

This does populate my list with multiple lines, but it takes each gallery item and multiplied it with the last quantity.

I added in a label (label1) which provides the value of qty/qty if the container is a mixed container, otherwise the label1 = qty

 

So if have 2 gallery items

   Destination: A - QTY: 3

   Destination: B - QTY: 5

Then my list currently gets 5 new items for both destination A and B, instead of 3 for destination A and 5 for destination B.

How do I make sequence use the QTY value for the correct gallery item? Should I use something other than sequence instead? Am I using Sequence in the wrong place in the formula?

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!

Top Solution Authors
Top Kudoed Authors
Users online (1,661)