cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Update DateField On IconAccept OnSelect

Solution I am Trying to Implement: Many of the tables that I have worked with have fields supporting auditing requirements, such as a createddate and modifieddate, or lastupdateddate field. The modified date should automatically update whenever the edit form is submitted.

 

Failed attempt 1: I tried adding a trigger to the database to update the modifieddate field on an update statement, but triggers aren't supported for SQL AZURE.

 

Failed attempt 2: I am trying to set the DateValue2.DefaultDate property from the OnSelect function of the IconAccept (checkmark in top banner of edit screen), but there seems to be no way to set the defaultdate programmatically.

 

What is the best way to update a date control's date/time value programmatically?

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Community Champion
Community Champion

Here is a demo:

 

1) Create a button and set its OnSelect to

UpdateContext({CurrentTime: Now()})

2) Create a text input and set its Default property to

Text(CurrentTime, UTC)

This should work, just add the UpdateContext to your IconAccept before the submit form

 

PS I do not use forms because I find them very inflexible, I just place individual controls.  You could resolve your issue by using the Patch() function to submit the updated record and just insert the Now() function directly in the Patch statement.

View solution in original post

6 REPLIES 6
Meneghino
Community Champion
Community Champion

Here is a demo:

 

1) Create a button and set its OnSelect to

UpdateContext({CurrentTime: Now()})

2) Create a text input and set its Default property to

Text(CurrentTime, UTC)

This should work, just add the UpdateContext to your IconAccept before the submit form

 

PS I do not use forms because I find them very inflexible, I just place individual controls.  You could resolve your issue by using the Patch() function to submit the updated record and just insert the Now() function directly in the Patch statement.

View solution in original post

Anonymous
Not applicable

Thanks @Meneghino, I will try implementing this, or something like it, and get back with you. One thing that you may have made me realize is that since I'm not allowing the user to update this data, there is no need to have the field presented as a date/time picker field. Thank you.

Meneghino
Community Champion
Community Champion

You are welcome, sounds like you are on the right track.

Do consider using a back-end that will do the work for you (i.e. time stamping).  CDS (Common Data Service) seems to be improving and I have been experimenting with it.  It should have what you need, and hopefully the PowerApps team will add more functionality to it with time.

Anonymous
Not applicable

Thanks @Meneghino for setting me on the right track. I made a slight modification to your answer:

 

On the ModifiedDate's Text property, I am using:

If(Not(IsBlank(CurrentTime)),CurrentTime,ThisItem.ModifiedDateTime)

 

CurrentTime will only be set once the IconAccept button is pressed, before then, I just want to display the last time the record was modified. This seems to work well, but do you see any issues that my inexperienced eye doesn't see?

 

Thanks again!

Meneghino
Community Champion
Community Champion

You are welcome @Anonymous 

I can't see any immediate issues, but again I have no experience with forms since I do not use them.

 

hpkeong
Community Champion
Community Champion

Hi @Anonymous

 

Just adding minor improvement to your formula to reduce braces (,).

Not(IsBlank(CurrentTime)) can be written as !IsBlank(CurrentTime)

- use ! to replace NOT

Example:

UpdateContext({Button: !Button}) will toggle the action of a button.

 

Thanks.

hpkeong

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

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (40,795)