Forum Discussion

EmberK's avatar
EmberK
Copper Contributor
Jan 03, 2024
Solved

SP field to allow for entry of year only but set default value to year of item created

Greetings - I am trying to see if it is possible to create a SP library column that would allow for the entry of a 4 digits/characters (to represent Year) but have the default value equal to the year...
  • EmberK's avatar
    Jan 03, 2024

    So for those who may have a similar issue, here is how I resolved this question (not sure if it is the best/only way, but this is where I landed).

     

    I think I discovered that while you can use Created Date as an operator in a calculated field, you cannot use it when setting an items default value.  Due to that, here was my solution...

     

    Created the new Date and Time column and set its default value to =TODAY().  Then used JSON column formatting (shown below) to display the field with the Year only.  This solution allows a user to accept the default value to be equal to the year in which they loaded the item, or edit the field and enter a different date.  This solution does require the user to enter a full date (m/d/yy) versus my idea to just collect the year, but the final result displays as I had envisioned.

     

    JSON script:

    {
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "span",
    "txtContent": "=getYear(@currentField)"
    }

Resources