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

Adding a simple timestamp

I'm sorry, I know this is a basic question, but I've just started PowerApps today, and can't seem to figure out what has to be a super-easy function.

 

The app I'm setting up is currently on OneDrive for Business, and is for users submitting information to a suggestion-box bounty for new ideas at our company. There's a reward involved, so these submissions need to be stamped with time and date upon creation, so if two people come up with the same idea, we know who suggested it first.

 

I'd like the app to automatically date and time stamp the current record in a specific field when the user clicks the Submit button. I've found a thousand ways to use Patch() to do advanced stuff, but can't figure out the simple solution to save my life. Can someone help me out with this?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Adding a simple timestamp

@ctishman 

Yeah, apparently they did...

 

Anyways, I copied the wrong code for you to use.  Try this instead.

SubmitForm(EditForm1);
Patch(
    HFAB_Proposals,
    Last(HFAB_Proposals), 
    {SubDate: Now()}
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

11 REPLIES 11
Highlighted
Super User
Super User

Re: Adding a simple timestamp

@ctishman 

You can use the NOW function to do this.  Here's a sample of how to use it in PATCH.

Patch(
    your_datasource_name,
    Defaults(your_datasource_name),
    {TimeStamp: Now()}
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Frequent Visitor

Re: Adding a simple timestamp

Thanks @mdevaney!

 

So I got that to successfully timestamp into the proper field of the current record, but because it uses the Defaults function, it also creates a second blank record at the time of submission. Do you know a way to have it apply this only to the current record? I'm reading through the syntax of the Patch function and it just doesn't make any sense to me.

 

I don't want to search and select from records, just timestamp the current record.

 

Currently it looks like this:

Patch(HFAB_Proposals, Defaults(HFAB_Proposals), {SubDate: Now()} );SubmitForm(EditForm1)

 

 

 

Thanks!

Highlighted
Super User
Super User

Re: Adding a simple timestamp

@ctishman 

Currently your code looks like this:

Patch(HFAB_Proposals, HFAB_Proposals.SubDate, {SubDate: Now()} );SubmitForm(EditForm1)

 

 The 2nd argument of patch will tell PowerApps what record to update.  Currently your code shows this.

HFAB_Proposals.SubDate

 

I would suggest changing it to a condition that looks at the current ID of the record and finds the matching one.  My assumption is you have a field called ID with a unique value for each record.  Try either one of these.

Patch(HFAB_Proposals, ID = DataCardValue_ID.Text, {SubDate: Now()} );SubmitForm(EditForm1)
Patch(HFAB_Proposals, ID = Value(DataCardValue_ID.Text), {SubDate: Now()} );SubmitForm(EditForm1)

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

Highlighted
Frequent Visitor

Re: Adding a simple timestamp

@mdevaney 

 

In terms of ID, I didn't explicitly create an ID column, but I do have the automatically-generated "__PowerAppsId__" column in the source Excel file, if that works.

 

Issue being, this function is being done to finalize the creation of the record, and takes place before the SubmitForm(EditForm1) bit, and so I don't think the form would have an ID yet at the time Patch is called.

 

I tried out both of your provided functions. When I used Value as follows, I got the following errors: 

Patch(HFAB_Proposals, ID = Value(__PowerAppsId__.Text), {SubDate: Now()} );SubmitForm(EditForm1)

"The function 'Value' has some invalid arguments."

"Name isn't valid. This identifier isn't recognized."

The function 'Patch' has some invalid arguments."

 

When I used it without the Value function:

Patch(HFAB_Proposals, ID = __PowerAppsId__.Text, {SubDate: Now()} );SubmitForm(EditForm1)

I got those errors as well as "Invalid use of '.'"

 

Thanks!

Highlighted
Super User
Super User

Re: Adding a simple timestamp

@ctishman 

Of the two patch statements I gave this is one I would model it after now that I have more info

 

Patch(HFAB_Proposals, ID = __PowerAppsId__.Text, {SubDate: Now()} );SubmitForm(EditForm1)

 

 

__PowerAppsId__.Text is giving an error because you need to reference a control (e.g. label, text input) with the ID value in it.  Something like this would be more appropriate.

 

Patch(HFAB_Proposals, ID = Label_PowerAppsID.Text, {SubDate: Now()} );SubmitForm(EditForm1)

 

 

As a test you could COPY + PASTE one of the PowerAppsID values hardcoded to see what I mean.  This example assumes "xpojg39jf" is the PowerApps ID of a record in your Excel sheet.

Patch(HFAB_Proposals, ID = "xpojg39jf", {SubDate: Now()} );SubmitForm(EditForm1

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Frequent Visitor

Re: Adding a simple timestamp

@mdevaney 

 

Unfortunately, PowerApps still says it's invalid, and I think I know why: the two underscores in "__PowerAppsID__" are part of the name (that field is automatically generated by PowerApps when it's given an Excel file to use as a data source, and the program uses that field to hold a unique generated record identifier).

 

Thus, the two underscores at the beginning of "__PowerAppsID__" immediately follow the underscore in "Label_", I end up with this:

 

Patch(HFAB_Proposals, ID = Label___PowerAppsID__.Text, {SubDate: Now()} );SubmitForm(EditForm1)

 

It still says I have an invalid name, though I'm not sure that's the cause. Since "__PowerAppsID__" is the primary record identifier, I can't change the name of the field, or PowerApps wouldn't be able to address its records, and in any case, the record being created doesn't have an ID until SubmitForm(EditForm1) runs.

 

Sorry if this is just dragging on and on. I appreciate your help.

Highlighted
Super User
Super User

Re: Adding a simple timestamp

@ctishman 

Maybe we just have these in the wrong order.  You could submit the form and then use LASTSUBMIT to find the ID of the record that was just created.  (Make sure I have the correct number of underscores)

 

SubmitForm(EditForm1);
Patch(
    HFAB_Proposals,
    ___PowerAppsID__: EditForm1.LastSubmit.___PowerAppsID__,
    {SubDate: Now()}
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Frequent Visitor

Re: Adding a simple timestamp

@mdevaney

 

I've modified it as you said, but PowerApps still doesn't like the name "__PowerAppsId__".

 

I'm wondering if they specifically gave that field an un-addressable name full of underscores to keep users from touching it.

Highlighted
Super User
Super User

Re: Adding a simple timestamp

@ctishman 

Yeah, apparently they did...

 

Anyways, I copied the wrong code for you to use.  Try this instead.

SubmitForm(EditForm1);
Patch(
    HFAB_Proposals,
    Last(HFAB_Proposals), 
    {SubDate: Now()}
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,505)