Sep 07 2023 04:14 AM - edited Sep 07 2023 05:09 AM
Hi all,
how do I get current date which is updated dynamically when a new day starts?
E.g I have a date column and a status column.
I want to set the status to "not due", "overdue" or "due" depending on the date column and the status column should provide filter functionality.
As I must learned a calculated column did not work because the today() function will only updating when the item has changed.
Could I do it somehow in PowerApps Form or is there some other way native in Sharepoint?
For some reassons Power Automate is not an option.
Sep 07 2023 04:41 AM
To achieve a dynamic "not due," "overdue," or "due" status based on the current date in SharePoint Online without using Power Automate, you can use JavaScript in SharePoint's column formatting feature. Here is a step-by-step guide:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"elmType": "span",
"style": {
"color": "=if([$DueDate] <= @now, 'red', if([$DueDate] < @now + 3, 'orange', 'green'))"
},
"txtContent": "=if([$DueDate] <= @now, 'Overdue', if([$DueDate] < @now + 3, 'Due Soon', 'Not Due'))"
}
]
}
This code checks if the "Due Date" is less than or equal to the current date (@now). If so, it sets the text to "Overdue" and the color to red. If the "Due Date" is within the next 3 days, it sets the text to "Due Soon" and the color to orange. Otherwise, it sets the text to "Not Due" and the color to green.
Now, when you view your SharePoint list, the "Status" column will dynamically update based on the "Due Date" column and the current date. Please note that this approach relies on client-side rendering, so it will work for views in SharePoint Online. However, users may need to refresh the page to see the status update as the date changes.The text and steps were created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark them as helpful and like it!
This will help all forum participants.
Sep 07 2023 05:07 AM
Sep 07 2023 01:20 PM
You are correct, approach will not provide filter functionality, was not a feature requested in the first message from you.The approach I provided using column formatting will not allow you to filter the results based on the dynamically calculated status. Column formatting is primarily for changing the visual representation of data within a column, and it does not affect the underlying data or its filtering capabilities.
If you need to filter the results based on the "not due," "overdue," or "due" status, you may need to consider alternative methods:
Ultimately, the choice of method will depend on your specific requirements, technical capabilities, and constraints within your SharePoint environment. Consider the trade-offs and limitations of each approach to determine the best fit for your needs. The text and steps were created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark them as helpful and like it!
This will help all forum participants
Oct 01 2024 05:37 AM
Hi @NikolinoDE, I've been trying to alter the JavaScript code with no success 🙂
I need today to be 'Due Soon' and today +1 and today +2 to also be 'Due Soon'. I also need today +3 and more to be 'Not Due'. Can you please show me how this JavaScript code will look like?
Thank you.
Oct 02 2024 08:07 AM
Oct 02 2024 08:09 AM
Oct 03 2024 11:00 AM
@pjallex this all needs to be done with JSON in your column formatting. JSON stands for Javascript Object Notation. Just calling it Javascript as an earlier poster did is not correct, but then I suspect the answer was looked up on ChatGPT.
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)
Oct 04 2024 01:41 AM
Oct 04 2024 03:24 AM