web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Canvas App Create "X" ...
Power Apps
Unanswered

Canvas App Create "X" number of records automatically

(0) ShareShare
ReportReport
Posted on 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

Categories:
I have the same question (0)
  • EddieE Profile Picture
    4,641 Moderator on at

    @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

  • jbaqueroc Profile Picture
    21 on at

    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 Moderator on at

    @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.

  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    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.

  • jbaqueroc Profile Picture
    21 on at

    @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

     

  • Verified answer
    Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    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 at

    @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.

  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    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.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard