cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper IV
Helper IV

Expression for created and modified time difference

Hello, 

 

I have this expression on the "on select" property of an edit button (pencil icon) that shows a pop up and will not let others edit a report (data source- SharePoint) if it wasn't created by them. 

 

If('Submitted By_DataCard3'.Default= User().FullName, EditForm('Incident Report- Edit');Navigate('Edit Incident Report',ScreenTransition.Fade), Set(showpopup2, true))

 

Now I need to add another condition in here. They are no longer allowed to modify a report if it has been 12 hours since they created it.  How would I add that to this expression?

 

Thanks

 

8 REPLIES 8
Super User III
Super User III

@TorreyFalconer 

You could use the DATEDIFF function to accomplish this task.  Change this section of your code:

'Submitted By_DataCard3'.Default= User().FullName

 

Into this code instead.

'Submitted By_DataCard3'.Default= User().FullName && DateDiff(Created, Now(), Hours) <= 12

 

---
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."

 

@mdevaney thanks, this does make sense to me...except for some reason it does not seem to be taking the 'created' property. Should that not always be available as it's part of the data source?

 

 

@mdevaney - 

 

See picture: I also tried replacing Created with:

'Created' 

Created()

'Created'.value

 

and then I also tried a workaround to actually put the created date control in the form but set to invisible and even then it wouldn't seem to take the datacardvalue

@TorreyFalconer 

Can you please show me where you are typing that code (what object and what property)?  Having a screenshot of the error message would also help 🙂

 

I've also changed by answer slightly from Created to ThisItem.Created assuming the code is in an Edit Form or Gallery

'Submitted By_DataCard3'.Default= User().FullName && DateDiff(ThisItem.Created, Now(), Hours) <= 12

 

---
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."

@mdevaney  whoops. For sure, that would be helpful information for you! See the screenshot below.

I am in view mode, in the onSelect property 

@TorreyFalconer 

Perfect!  I know exactly what the issue is 🙂

 

The error message means a screen or object has been deleted/renamed but is still being referred to in your code.  I think its one of these two screens.  Check if they still have a matching name on your left side menu.

 

EditForm('Incident Report- Edit');Navigate('Edit Incident Report',ScreenTransition.Fade)

 

---
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."

@mdevaney well that was a second issue that I totally didn't notice so thanks! But still not working, it does seem to be the 'Created' reference because when I hover over it, it says name isn't valid. But I've also tried it in so many variations (created, created(), thisitem.created, created.value, value.created, 'created', then tried adding a control in the app on invisible and tried: datacard14value. and created_datacard1.value etc etc)

@TorreyFalconer
Now I also know why Created is giving you problems. Your button is outside of the Edit Form (which is totally normal). However, you cannot reference the Created field while outside the form. It makes kinda makes sense because PowerApps is saying “where should I get the Created field from where exactly?

You can get around this by storing the value of Created in a variable and referencing the variable instead. Did you browse to the Edit screen from a gallery? If yes, you can put this code in the OnVisible property of your Edit Screen.

Set(varCreated, Gallery1.Selected.Created)

Then in your DateDiff formula simply replace Created with varCreated.

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

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (88,547)