In a recent query from a reader on List Formatting and setting field values on Microsoft Lists, a reader sought help to automatically populate a date column with the current date when an action button is clicked. This is intended to simplify the process for executives to confirm the completion of a work trip.
It is possible to set a SharePoint Date only field to the current date using JSON List Formatting. The customRowAction attribute coupled with setValue action type can be utilized for this task. The @now token is used to retrieve the current date/time automatically and can be formatted to show the date only by generating a string in the 'yyyy-MM-dd' format.
A code sample demonstrates how to create a custom button that, on being clicked, sets a Date only field named 'Date Trip Completed' to the current date. If a date has already been set, it displays the date without showing the button to mark the trip as complete. The JSON provided can be applied with just a change to the field name, if different.
The result of applying this formatting template is a functional button that sets the date field's value to the current one upon clicking. However, the process and technical specifics of the implementation are not displayed in this summary.
The post concludes with references to the Formatting Syntax Reference on Microsoft Learn, where readers can find further information on List Formatting in SharePoint.
SharePoint List Formatting allows users to customize the appearance and behavior of list data using JSON. This enables users to add dynamic elements like action buttons to lists, enhancing interactivity and user experience. With JSON List Formatting, users can display data in various ways, set conditions for formatting, and trigger actions such as setting field values. In professional settings, such as the user's intention in our example, this can be especially useful for streamlining processes and creating a user-friendly interface that fits into workflows, such as confirming the completion of work travel. It requires a solid understanding of both SharePoint and JSON syntax but provides a powerful toolset for tailoring list views to meet specific business needs.
In a recent query highlighted on a blog, a reader inquired about adding an action button to a Microsoft list that automatically sets a trip date column to the current date when pressed. This feature would help executives easily confirm the completion of their work trips. Questions arose whether this could be accomplished using SharePoint List Formatting with JSON coding.
The solution involves utilizing the 'customRowAction' attribute with the 'setValue' action type in SharePoint List Formatting. This technique sets the field value to the current date by using the unique '@now' token that automatically identifies the current date and time.
To exclusively set the date field, one can construct a string formatted as 'yyyy-MM-dd'. The following example demonstrates the JSON configuration to achieve this result:
Michel Mendes provides an example code where a field named 'Date Trip Completed' is formatted to reflect the current date upon clicking a button. If a date is already present, the formatted date is displayed and the 'Mark as complete' button is not shown.
The provided JSON example can be applied to implement the aforementioned feature by making sure to replace the field name as needed. Below is the JSON structure you can use:
With this SharePoint List Formatting template applied to a column, users can effectively set a date field to the current date with the click of a button. While the detailed JSON structure and elements are omitted for brevity, the concept showcases the power of customization in SharePoint Lists.
References are provided to the formatting syntax reference documentation on Microsoft Learn for readers who seek to dive deeper into List Formatting in SharePoint. However, external links and animated examples are excluded from this summary.
To format a date column in SharePoint JSON, you would use the "DateTime" mode in the "Column Formatting" section. By specifying the "format" element with an appropriate date string pattern, you can customize the display of the date in your SharePoint list or library. For example, use the format "toLocaleDateString()" to transform the date into a readable string based on the local date format.
To create a current date column in SharePoint, you will need to add a calculated column to your SharePoint list or library. In the formula section of the calculated column, you can use the [Today] shortcut to automatically use the current date. Please note that this calculated field will only be updated when an item is edited or added, not each day automatically.
Getting only the date in a SharePoint list, without the time, requires adjusting the settings of your Date and Time column. Go to the list settings, click on the Date and Time column you wish to adjust, and set the "Date and Time Format" to "Date Only." This ensures that only the date part will be displayed and used throughout your list.
To format the date column in a SharePoint list, access the list's column settings and modify the "Column Formatting" section by providing a custom JSON object. Here, you can utilize predefined tokens and patterns to control how your dates are displayed, such as "yyyy-MM-dd" for an international standard date format or "MM/dd/yyyy" for a more US-centric format.
SharePoint List Formatting, SharePoint Date Field, Current Date JSON, SharePoint JSON Formatting, Set SharePoint Date, Current Date List Field, SharePoint Field Customization, SharePoint Date Automation, SharePoint JSON Date, SharePoint List Date Update