Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 2GPsdEPHbtUQ44dg0O6Urq
Power Apps - Building Power Apps
Answered

Canvas App Create "X" number of records automatically

Like (0) ShareShare
ReportReport
Posted on 13 Feb 2023 21:43:56 by 21

Hi all, 

 

I am building an app using SP lists that follows a workprocess, in a previous step an user will input a number of records (variable) to be created in an upcoming process step, Now I want the app to automatically to create those "X"number of records (Varholeqtty), for this I am Using this code:

If(
 CountRows(datadrill) = 0,
 ForAll(
 Sequence(Varholqtty),
 Collect(
 datadrill,
 Patch(
 varNewLog,
 {
 ID: varNumber,
 'Blast #': var_Blast,
 'Hole #': First(ColHoleQtty).Result,
 'Drill Depth': {Value: Text("0-10")}
 }
 )
 );
 If(
 First(ColHoleQtty).Result = Varholqtty,
 UpdateIf(
 ColHoleQtty,
 Result = Varholqtty,
 {Result: 1}
 ),
 UpdateIf(
 ColHoleQtty,
 Result < Varholqtty,
 {Result: Value(Result) + 1}
 )
 )
 );
 ForAll(
 Sequence(Varholqtty),
 Collect(
 datadrill,
 Patch(
 varNewLog,
 {
 ID: varNumber,
 'Blast #': var_Blast,
 'Hole #': First(ColHoleQtty).Result,
 'Drill Depth': {Value: Text("10-20")}
 }
 )
 );
 If(
 First(ColHoleQtty).Result = Varholqtty,
 UpdateIf(
 ColHoleQtty,
 Result = Varholqtty,
 {Result: 1}
 ),
 UpdateIf(
 ColHoleQtty,
 Result < Varholqtty,
 {Result: Value(Result) + 1}
 )
 )
 )
)

   I am using a collection and a ForAll function to sequence the "Hole #"records with an +1step in each one.

 

The records are being succesfully created on the SP list, but the app got inestable and gets stuck, I have to kill it and restart it each time.

 

How could I improve this code? Thanks in advance.

Juan

  • Pstork1 Profile Picture
    66,015 Most Valuable Professional on 14 Feb 2023 at 19:10:57
    Re: Canvas App Create "X" number of records automatically

    YOu can create the flow anywhere as long as you use one of the two power app triggers in the flow. I suggest the V2 trigger.  Then you can execute the flow from any behavioral property in your app.  OnSelect on a button is most common, but it will work on any On... property.

  • jbaqueroc Profile Picture
    21 on 14 Feb 2023 at 19:01:52
    Re: Canvas App Create "X" number of records automatically

    @Pstork1 yes I got that, as I understand I need to create that flow using the power automate menu inside powerapps (so it will be triggered from my app), and then assign the flow to a button or other control on the app to execute the flow and create the records on the SP list (therefore display those on the app). Makes sense?

    The tricky part will be to create that flow lol.

     

    Thanks for your advice and pointing me in this direction.

  • Verified answer
    Pstork1 Profile Picture
    66,015 Most Valuable Professional on 14 Feb 2023 at 18:14:11
    Re: Canvas App Create "X" number of records automatically

    Sorry if I wasn't clear.  Its not Power Apps or Power Automate, its a combination of the two.  When the user enters that they need 100 holes inspected you pass 100 and any other pertinent information to the flow, like who to assign it to.  The flow then does a loop on 100 and creates 700 records filling in the appropriate info as supplied. Once created it returns to the Power App.  When another user enters the Power App it pull up the appropriate records that were created for them.  At that point its just power apps.

  • jbaqueroc Profile Picture
    21 on 14 Feb 2023 at 17:10:12
    Re: Canvas App Create "X" number of records automatically

    @Pstork1 & @EddieE Thanks for the help, 

     

    A little bit more of context, an user will define a number of inspections "holes" to be done by somebody in the field (this is the variable varholeqtty) then the person on the field has to go and inspect 7 different parts in each of this holes (this is Drill depth field and goes by 10 increments from 0-70 ), therefore if I want to have 100 holes I need to create 700 records.

     

    What I want is to automatically create part o this records so for the guy on the field once he opens the screen a prefilled form with the 700 records will pop-up and he will just have to select some options from some dropdowns fields.

     

    I do believe that the Canvas power app struggles a lot with this and probably is not intended for my purpose, I will try to go with the PA flow but I haven't used this in the past. If you have any further suggestion or tutorial to recommend me it will be greatly apprecciated.

     

    Juan

     

  • Pstork1 Profile Picture
    66,015 Most Valuable Professional on 14 Feb 2023 at 03:40:20
    Re: Canvas App Create "X" number of records automatically

    I would suggest looking at a completely different way to do this.  Create a Power Automate flow that takes the number of records to create as an Input parameter. Then have the flow create the records and send back the ID of the first record in the range created. This would be fairly quick and a lot more stable than doing it in Power Apps, which isn't really designed to be procedural and do things like loops.

  • EddieE Profile Picture
    4,641 Super User 2025 Season 1 on 14 Feb 2023 at 02:29:39
    Re: Canvas App Create "X" number of records automatically

    @jbaqueroc 

    I'm a little confused about what you are trying to achieve, can you explain the  full process that a user would go through. If you have relevant code, post that as well.

  • jbaqueroc Profile Picture
    21 on 14 Feb 2023 at 02:10:40
    Re: Canvas App Create "X" number of records automatically

    Hi @EddieE 

    Thanks for your Help, 

    When doing this I got an error because the varNewLog is a record, so the patch is expecting a single record instead of a table.

    varNewLog is defined with the function Default to the SP List, same Sp List used in the collection Datadrill (so data will match exactly).

     

    How can I sove this?

     

    Juan

  • EddieE Profile Picture
    4,641 Super User 2025 Season 1 on 14 Feb 2023 at 01:17:33
    Re: Canvas App Create "X" number of records automatically

    @jbaqueroc 

    You could try a different approach with your Patch() & ForAll(), ie

     

    Collect(
     datadrill,
     Patch(
     varNewLog,
     ForAll(
     Sequence(Varholqtty),
     {
     ID: varNumber,
     'Blast #': var_Blast,
     'Hole #': First(ColHoleQtty).Result,
     'Drill Depth': {Value: Text("0-10")}
     }
     )
     )
    );
    
    

    This method patches a Table rather than Record by Record, so a little faster and may fix the issue?

     

    It may also depend on how many records are being created each time. I just tested the above code using 500 as my Sequence() value and it took around 25-30secs

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard