cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
sanderson82
Level: Powered On

Timer loop - Set starting number, fully reset

Hi, I'm developing an app to create a record and qty of products.  In summary user will select the project, type the unit/product name, quantity required and some other detail (volume, weight, rebar).  I then have a timer which adds records to a collection based on the quantity required.  If 3 for example it creates the unit names with 001, 002 an 003 after the name.

 

Issues

1) The timer does not fully reset, I have had to add a second button to reset the timer.  Without this second button, as soon as I amend the qty more units are added to the collection

2) There is a requirement that I may need to create 10 units, then come back at a later time and create another 10 units, however on the 2nd occasion I would need the sequence to start from 11.

 

Please see code below and a screenshot of how the app is laid out.  The blank pane to the left is where I would like to show any units already created based on the project/contract selected.  If possible I would like to use this to select a product / unit if I'm adding additional units of the same type at a later date, and the system knows then automatically what sequence number to start on.

 

OnTimerStart

Collect(
    Units,
    {
        Title: I_Contract_1.SelectedText.Value,
        Unit: Upper(I_Unit_1.Text),
        Volume: Value(I_Volume_1.Text),
        Weight: Value(I_Weight_1.Text),
        Rebar: Value(I_Rebar.Text),
        Count: Value(I_Count_1.Text),
        Sequence: Text(Value(number),"[$-en-GB]000"),
        Status: "Required"   
    }
   );
UpdateContext({number:number+1})

 

OnTimerEnd - False

OnSelect - UpdateContext({number:1})

Start - False

Duration - 100

Repeat - number <= Value(I_Count_1.Text)

Reset - False

Autostart - False

AutoPause - False

 

Second reset button (tick icon)

Reset(I_Count_1);Reset(I_Unit_1);Reset(I_Volume_1);Reset(I_Rebar);Reset(Timer2_1)

 

 Any help much appreciated.  Hopefully this also assists others

7 REPLIES 7
Dual Super User
Dual Super User

Re: Timer loop - Set starting number, fully reset

Hi @sanderson82 

 

Can you try to set the configuration as:

OnSelect: UpdateContext({number:1});Set(RunTimer,true)
Repeat: RunTimer
OnStart:
If(number > Value(TextInput1.Text),Set(RunTimer,false),Collect(
Units,
{
Title: I_Contract_1.SelectedText.Value,
Unit: Upper(I_Unit_1.Text),
Volume: Value(I_Volume_1.Text),
Weight: Value(I_Weight_1.Text),
Rebar: Value(I_Rebar.Text),
Count: Value(I_Count_1.Text),
Sequence: Text(Value(Last(Sort(Units,Sequence,Ascending)).Sequence)+1,"[$-en-GB]000"),
Status: "Required"
}
);
UpdateContext({number:number+1}))

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

sanderson82
Level: Powered On

Re: Timer loop - Set starting number, fully reset

Hi @yashag2255 thanks for your response.  I've updated my code to reflect your response however the timer sequence does not reset each time.  So if I run once for 3 units.  When I go to do another 5 units of a different type for example the timer starts at 4.  

 

I would need this to reset each time, but also have a text input that would allow me to manually change the start number of the sequence if required

 

Hope that makes sense.

Dual Super User
Dual Super User

Re: Timer loop - Set starting number, fully reset

Hey @sanderson82 

 

If you do not want to continue from the last entered value in the collection and reset it everytime, you need to update the expression as:

OnSelect: UpdateContext({number:1});Set(RunTimer,true)
Repeat: RunTimer
OnStart:
If(number > Value(TextInput1.Text),Set(RunTimer,false),Collect(
Units,
{
Title: I_Contract_1.SelectedText.Value,
Unit: Upper(I_Unit_1.Text),
Volume: Value(I_Volume_1.Text),
Weight: Value(I_Weight_1.Text),
Rebar: Value(I_Rebar.Text),
Count: Value(I_Count_1.Text),
Sequence: Text(Value(number),"[$-en-GB]000"),
Status: "Required"
}
);
UpdateContext({number:number+1}))

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

sanderson82
Level: Powered On

Re: Timer loop - Set starting number, fully reset

Hi @yashag2255 

 

I have it working as I need with the following code

Collect(
Units,
{
Title: I_Contract_1.SelectedText.Value,
Unit: Upper(I_Unit_1.Text),
Volume: Value(I_Volume_1.Text),
Weight: Value(I_Weight_1.Text),
Rebar: Value(I_Rebar.Text),
Count: Value(I_Count_1.Text),
Sequence: Text(Value(number),"[$-en-GB]000"),
Status: "Required"
}
);
UpdateContext({number:number+1});
UpdateContext({count:count+1})

 

OnSelect: UpdateContext({number:Value(I_StartNo.Text)});UpdateContext({count:1})

 

Repeat: count <= Value(I_Count_1.Text)

 

Reset: count > Value(I_Count_1.Text)

 

This resets the timer as required but also lets me adjust that seq start number.

 

I also have the text input reset set to "count > Value(I_Count_1.Text)" however I can't seem to figure out how I reset I_Count when the timer is finished

Dual Super User
Dual Super User

Re: Timer loop - Set starting number, fully reset

Hey @sanderson82 

 

If you want to provide the start number value and the count of items, you can update the expression as:

OnSelect: UpdateContext({number:Value(I_StartNo.Text), count:1});Set(RunTimer,true)
Repeat: RunTimer
OnStart:
If(count > Value(I_Count_1.Text),Set(RunTimer,false),Collect(
Units,
{
Title: I_Contract_1.SelectedText.Value,
Unit: Upper(I_Unit_1.Text),
Volume: Value(I_Volume_1.Text),
Weight: Value(I_Weight_1.Text),
Rebar: Value(I_Rebar.Text),
Count: Value(I_Count_1.Text),
Sequence: Text(Value(number),"[$-en-GB]000"),
Status: "Required"
}
);
UpdateContext({number:number+1,count:count+1}))

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

sanderson82
Level: Powered On

Re: Timer loop - Set starting number, fully reset

Thanks @yashag2255  can you advise how I can reset my text inputs to default when the timer is complete?

Dual Super User
Dual Super User

Re: Timer loop - Set starting number, fully reset

Hi @sanderson82 

 

To reset the inputs, update the expression on the OnStart as:

If(count > Value(I_Count_1.Text),Set(RunTimer,false);Reset(I_Count_1);Reset( I_Contract_1);Reset(I_Unit_1);Reset(I_Volume_1);Reset(I_Weight_1);Reset(I_Rebar);Reset(I_StartNo),Collect(
Units,
{
Title: I_Contract_1.SelectedText.Value,
Unit: Upper(I_Unit_1.Text),
Volume: Value(I_Volume_1.Text),
Weight: Value(I_Weight_1.Text),
Rebar: Value(I_Rebar.Text),
Count: Value(I_Count_1.Text),
Sequence: Text(Value(number),"[$-en-GB]000"),
Status: "Required"
}
);
UpdateContext({number:number+1,count:count+1}))

This will reset all the controls when the timer is completed. Please add in case I might have missed any of the control.

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,811)