List-Formatting icon indicating copy to clipboard operation
List-Formatting copied to clipboard

Any Idea how to setValue to a datetime Field?

Open dborchers-gc opened this issue 4 years ago • 12 comments

Hi, i´ve tried to set a datetime value to a datetime field with the setValue actiion. But in eveery case i tried it only sets the date with 00:00 as time string.

Any idea how to sollve it? here is my code:


{
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "gesperrt": "False",
          "Changes_Counter": 0,
          "Changed_Members": "0",
          "Changed_Functions": "0",
          "Changed_GeneralData": "0",
          "Changed_Admins": "0",
          "Changed_Owners": "0",
          "Change": "=toDateString(@now)"
        }
      },
      "style": {
        "border": "none",
        "pointer-events": "=if( (([$gesperrt] == True), 'auto', 'none')"
      },
      "children": [
        ...
      ]
    }
  ]
}

dborchers-gc avatar Jan 26 '22 06:01 dborchers-gc

Change is my DatetIme Field i want to update

dborchers-gc avatar Jan 26 '22 06:01 dborchers-gc

Hi, @dborchers-gc !!

Try removing the toDateString and changing it to the following.

          "Change": "@now"

tecchan1107 avatar Jan 26 '22 07:01 tecchan1107

Hi, @dborchers-gc !!

Try removing the toDateString and changing it to the following.

          "Change": "@now"

no sorry, it doesnt work. Only @now seems to also set only the date

dborchers-gc avatar Jan 26 '22 07:01 dborchers-gc

Can you give a look in this repo sample, maybe can help you https://github.com/pnp/List-Formatting/tree/73f8fb4b71e21403a9084a2ec085cb122ab93b55/column-samples/date-update-format

aaclage avatar Jan 26 '22 10:01 aaclage

Hey Guys, maybe i found the reason why its not working for me but i have no idea how to solve it.

The problem seems to be taht the setValue function with the "@now" value would st a dateime with seconds in it. But the standard datetime fields need a datetime value with only hh:mm

Ive Test that in a simple text field, you see here. Any idea? 2022-09-16 07_16_06-Microsoft 365 Self-Service-Portal - TEST-Diff - Alle Elemente und 10 weitere Sei

dborchers-gc avatar Sep 16 '22 05:09 dborchers-gc

here is the code:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "flex-directon": "row",
    "justify-content": "left",
    "align-items": "center",
    "flex-wrap": "nowrap"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "inherit",
        "flex-directon": "row",
        "justify-content": "left",
        "align-items": "center",
        "flex-wrap": "wrap"
      },
      "children": [
        {
          "elmType": "button",
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "TextDate": "=@now"
            }
          },
          "attributes": {
            "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
          },
          "style": {
            "border": "none",
            "background-color": "transparent",
            "cursor": "pointer",
            "display": "flex",
            "flex-directon": "row",
            "justify-content": "left",
            "align-items": "center",
            "flex-wrap": "wrap"
          },
          "children": [
            {
              "elmType": "span",
              "attributes": {
                "iconName": "CircleAdditionSolid"
              },
              "style": {
                "padding": "4px"
              }
            },
            {
              "elmType": "span",
              "txtContent": "CHANGE",
              "style": {
                "word-break": "keep-all"
              }
            }
          ]
        }
      ]
    }
  ]
}

dborchers-gc avatar Sep 16 '22 05:09 dborchers-gc

Hi @dborchers-gc,

Did you try with the date format of your site?`

"actionInput": {
"TextDate": "= getMonth(@now)+'/'+getDate(@now)+'/'+getYear(@now) +' 00:00 AM'" 
}

aaclage avatar Sep 16 '22 06:09 aaclage

@aaclage that works but i need the time too.

At the end i just want to compare my own datetime with the modified datetime and if the difference is to high something would happen - thts my whole usecase

But i want to have a way where i can set the owndate by setValue action in JSON, by powershell and by powerautomate action

dborchers-gc avatar Sep 16 '22 06:09 dborchers-gc

@dborchers-gc

You also need the seconds?

aaclage avatar Sep 16 '22 07:09 aaclage

Yes i guess it would be better

dborchers-gc avatar Sep 16 '22 07:09 dborchers-gc

But Maybe you have another idea. Here is my whole usecase:

A Power Automate Flow cannot start directly after changing a list item but i would like to lock editing the list item after changing some values in it. I tried to do that with a custoimdatetime-field and i comparte the modified field with this custoimdatetime-field

My Flows will change this custoimdatetime-field too but the user cannot change it. So i think i will have a way to see differneces between changes from the uiser and changes from my flows

dborchers-gc avatar Sep 16 '22 07:09 dborchers-gc