cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Aschwinb
Frequent Visitor

MS PowerApps timestamp button doesn't work

0
 

I am trying to make an app where a user can click a button 'start' when he starts an action and 'stop' when he stops an action. Both of these actions should result in adding a timestamp to the record (column in excel file)

the following function is linked to my button 'start':

 

OnSelect = Patch( Planning, First(Filter( Planning, StartTime = "" ) ), { StartTime: Text( Now() ) } )

 

(Planning is the name of the table in my excel file, StarTime= name of the column in Excel where the timestamp should be added)

When I try the app, clicking the button doesn't result in an addiction of the timestamp in my excel file.

link to pictures of powerapps and excel table: https://imgur.com/a/XgQF56y

 

What is wrong with my function/code?

 

Thanks in Advance!!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
timl
Super User III
Super User III

Hi @Aschwinb 

Could you replace the commas with semi-colons to see if that makes a difference?

Patch( Planning; First(Filter( Planning; StartTime = "" ) ); { StartTime: Text( Now() ) } )

If not, could you click the red error icon that appears next to the start button and let us know what the error message is?

 

View solution in original post

Hi @Aschwinb 

Another way is to store the record that you just updated in variable. If you then click the Start button again, you can modify your formula so that it updates the last updated record, rather than the next record with a blank start time.

In the OnVisible property of your screen, you can initialise a variable called LastUpdatedRecord like so.

Set(LastUpdatedRecord, Blank())

You can then modify your Patch function like so:

Set(LastUpdatedRecord;
    Patch( Planning;
           If(IsBlank(LastUpdatedRecord); 
First(Filter( Planning; StartTime = "" ) );
LastUpdatedRecord
); { StartTime: Text( Now() ) } ) )

View solution in original post

6 REPLIES 6
timl
Super User III
Super User III

Hi @Aschwinb 

Could you replace the commas with semi-colons to see if that makes a difference?

Patch( Planning; First(Filter( Planning; StartTime = "" ) ); { StartTime: Text( Now() ) } )

If not, could you click the red error icon that appears next to the start button and let us know what the error message is?

 

View solution in original post

Aschwinb
Frequent Visitor

Still doesn't work 😞

this is the error I get: translated: the requested ressource is locked. Serverresponsibility: Can't write file to filesource. file is locked.........


@timl wrote:

Hi @Aschwinb 

Could you replace the commas with semi-colons to see if that makes a difference?

Patch( Planning; First(Filter( Planning; StartTime = "" ) ); { StartTime: Text( Now() ) } )

If not, could you click the red error icon that appears next to the start button and let us know what the error message is?

 


 

 

Schermafbeelding 2019-06-27 om 14.00.31.png

timl
Super User III
Super User III

Hi @Aschwinb 

The syntax with semi-colons appears correct because the function names in your formula bar are now coloured correctly.

The 'resource locked' error typically occurs when your Excel file is open somewhere else. To resolve this, I would make sure that the file isn't opened elsewhere, or by another user. Once you're sure this is the case, I would try again.

Aschwinb
Frequent Visitor

Ok that was the problem, thank you so much!

Now I have one more problem, when I click 2 times on the start button, it writes a timestamp on the next row of my excel table (which is new 'ship' in my case), while I want every ship to be unique and only have one timestamp.

When I click on 'start' for ship with surveyor A for 2 times, instead of overwriting the time for start, it adds a new timestamp for ship with surveyor B, which I don't want.

 

Schermafbeelding 2019-06-27 om 14.39.44.pngSchermafbeelding 2019-06-27 om 14.39.34.png

Hi @Aschwinb ,

I suggest you change your formula about filter data.

Try this formula:

Patch( Planning; ThisItem ; { StartTime: Text( Now() ) } )

The reason why you met the problem is that if you click once the start button, the original item's StartTime field will not be blank. So if you click the start button twice, the patched item will be the next one.

 

Best regards,

Community Support Team _ Phoebe Liu

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Aschwinb 

Another way is to store the record that you just updated in variable. If you then click the Start button again, you can modify your formula so that it updates the last updated record, rather than the next record with a blank start time.

In the OnVisible property of your screen, you can initialise a variable called LastUpdatedRecord like so.

Set(LastUpdatedRecord, Blank())

You can then modify your Patch function like so:

Set(LastUpdatedRecord;
    Patch( Planning;
           If(IsBlank(LastUpdatedRecord); 
First(Filter( Planning; StartTime = "" ) );
LastUpdatedRecord
); { StartTime: Text( Now() ) } ) )

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (15,146)