SOLVED

JSON syntax clickable button to capture/record the time and date now

Copper Contributor

Looking for help please.

 

i have a list that requires to capture the time after the task is complete. is there a way using json sysntax to create a clickable button then the action will be to capture the date and time now?

 

i saw this i microsoft site, but instead of sending an email as an action i need to capture the date and time now.

 

Abbyamante_0-1627081030661.png

Abbyamante_1-1627081054311.png

 

 

6 Replies
You can try using a new field to capture the utcnow() value, I'm using that option to capture the time when any user changes some list.. Did you tray a solution using flows?
No. i havent tried using or building anything yet. just wanted to get some ideas how to achieve this without using flows.

@Abbyamante 

I've done a little digging since I'm new to "Modern SharePoint", but have been customizing older versions of SharePoint for some time now.

 

The example you provided works well since it creates a simple HTML link for each item in the list. The functionality is then based on browser and default mail client for the PC.

 

I'm not sure if you can do the same exactly since you need to update the list item. If you can find a way to update a list item via URL + query string then you could probably use the JSON approach you've provided. 

 

It does look like you can achieve what what you want with a combination of customizations. You could add a custom row action button that opens the edit form dialog. You could then create a custom "edit form" by creating a PowerApps form for it. I tried this out and added a button control that would set a "completed" date field to the current date/time. I used this PowerUsers question and answer (see RandyHayes answer) to help figure it all out. In theory you could hide all other controls except the date field with "complete now" button on this custom edit form. It's a three click solution (edit button from list item > Complete now button from custom form > Save) but it does streamline it to the effect I think you are looking for

 

I think with a bit more work you might be able to customize a form specifically for the "on save" action in PowerApps that would strictly save the current date and time to your desired field. You could then use this guy's technique to target a specific form using JSON scripting (see the last half of his guide) as you were aiming to do with this question.

 

Sorry, long winded response. I was curious myself how this might be done. It looks like a lot, but I think it can be done with the resources I linked and the PowerApps know how. All-in-all, a power automate flow might actually be easier...

this is very well explained, no apologies necessary. thank you for your response. i agree, it seems like the only way to achieve this is using the flow.

thank you again,
best response confirmed by Abbyamante (Copper Contributor)
Solution

@Abbyamante you could trigger a flow with a JSON-formatted button but you don't need to, it can all be done automatically with a fairly simple flow in Power Automate.

 

First in your list settings -> versioning settings you MUST turn on item version history. This is because we comparing the current version with the previus one.

 

In this example we have  status column which is a choice type and a Completed column which is datetime and includes the time. We will be checking to see if the Status column has changed AND the status is now Complete. If this is the case it will update the Completed column with the current date and time.


0-SPList-Versioning.png

 The trigger in Power Automate is the SharePoint when an item or a file is modified. Select your site and list.

 

1-Flow.png

 

Then the first action in the flow is to get changes for an item or a file (properties only). In the ID field select ID from the dynamic content box on the right. In the since field you need an expression so over in the dynamic content box click the Expression tab and copy&paste the following expression in then click the OK button (mine shows as Update as I have previously added the expression):

sub(int(triggerOutputs()?['body/{VersionNumber}']),1)

 

2-Flow.png

 

Next, add a condition and in the left field select Has Column Changed: Status from the dynamic content then select is equal to then in the right field type true

 

3a-Flow.png

 

Then add a new row and select Status Value for the left field (it's Status Value and not just Status as the column is a choice column), then select is equal to and in the right field type Completed

 

3b-Flow.png

 

The conditin gives you a red if no channel which you can leave empty and a green if yes channel where you add an Update item action. You'll need to select your site and list again, select ID from the dynamic content box and any other columns which are mandatory which in my case is title. Then in the  Completed field add an expression of utcNow()

 

4-Flow.png

 

So in this case we update the Bedar item to a status of completed:

5-SPList-StatusChanged.png

 

The flow runs and updates it with the current date and time. It can take a 10 or 20 seconds sometimes for the flow to complete and add the date/time in: 

 

6-SPList-Completed.png

Rob
Los Gallardos
Microsoft Power Automate Community Super User 

 

thank you so much for this idea! its very well explained and all the pictures helps a lot to easily follow step by step how it gets done!

thank you so much!
1 best response

Accepted Solutions
best response confirmed by Abbyamante (Copper Contributor)
Solution

@Abbyamante you could trigger a flow with a JSON-formatted button but you don't need to, it can all be done automatically with a fairly simple flow in Power Automate.

 

First in your list settings -> versioning settings you MUST turn on item version history. This is because we comparing the current version with the previus one.

 

In this example we have  status column which is a choice type and a Completed column which is datetime and includes the time. We will be checking to see if the Status column has changed AND the status is now Complete. If this is the case it will update the Completed column with the current date and time.


0-SPList-Versioning.png

 The trigger in Power Automate is the SharePoint when an item or a file is modified. Select your site and list.

 

1-Flow.png

 

Then the first action in the flow is to get changes for an item or a file (properties only). In the ID field select ID from the dynamic content box on the right. In the since field you need an expression so over in the dynamic content box click the Expression tab and copy&paste the following expression in then click the OK button (mine shows as Update as I have previously added the expression):

sub(int(triggerOutputs()?['body/{VersionNumber}']),1)

 

2-Flow.png

 

Next, add a condition and in the left field select Has Column Changed: Status from the dynamic content then select is equal to then in the right field type true

 

3a-Flow.png

 

Then add a new row and select Status Value for the left field (it's Status Value and not just Status as the column is a choice column), then select is equal to and in the right field type Completed

 

3b-Flow.png

 

The conditin gives you a red if no channel which you can leave empty and a green if yes channel where you add an Update item action. You'll need to select your site and list again, select ID from the dynamic content box and any other columns which are mandatory which in my case is title. Then in the  Completed field add an expression of utcNow()

 

4-Flow.png

 

So in this case we update the Bedar item to a status of completed:

5-SPList-StatusChanged.png

 

The flow runs and updates it with the current date and time. It can take a 10 or 20 seconds sometimes for the flow to complete and add the date/time in: 

 

6-SPList-Completed.png

Rob
Los Gallardos
Microsoft Power Automate Community Super User 

 

View solution in original post