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
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.
@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.
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.
@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
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.
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.
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
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
WarrenBelz
146,763
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional