Render based on today's date

  • 1
  • Question
  • Updated 2 years ago
  • In Progress
I'm trying to render a component (specifically a Panel Set) based on Today's date. I don't currently have a field in any of my models with a date = Today. So, if Today is before end of month, show this panel set. If it is after the end of this month, show that panel set. Anyone do this before?
Photo of Ryan Faust

Ryan Faust

  • 884 Points 500 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Ryan,
Do you mind clarifying what you mean by "If Today is before end of month" and "if it is after the end of this month"? Are you looking at a particular field value (e.g. a date field), or just today's date in general? I think I'm missing something on that logic.

If the condition is dependent on something other than a field value, model/row property, running user attribute, or url parameter, you may be able to get what you need through a render condition with "Snippet returns true" as the Source Type. If you can provide a little more detail on the logic you're trying to achieve, I'd be glad to try to help.

Thanks,
Emily
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Hm, so you are saying you want to render one message if today is before April 20th, and another message if today is after April 20th? Where does the April 20th come from? Is that date based on a field on a model?
Photo of Ryan Faust

Ryan Faust

  • 884 Points 500 badge 2x thumb
The date is based on a business trigger for when we go live with a customer message. I don't have a field in the model that refers to that date at all. But, the April 20th date is a hard date. You are correct with the logic, message 1 for if today is before April 20th. Message 2 if today is April 20th or after.
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Ryan,
That makes more sense that April 20 is a firm value based on a go-live date. I think you can achieve this with a Ui-only model. Create a field on your Ui-only model with Display Type "Formula" and Formula Return Type "Date". Your formula would simply be: TODAY().

Then, for each page message, you can add a render condition based on that Ui-only model's field value (formula field's value is less than a specified date, formula field's value is greater than or equal to that specified date).

Here's my render condition (using 3/22 as the go-live date):





Let me know how that works.
Emily
(Edited)
Photo of Ryan Faust

Ryan Faust

  • 884 Points 500 badge 2x thumb
This makes total sense. I guess where I am struggling is the actual formula. I'm not a programmer, so I don't think I have the right {{}} or something. Can you tell me exactly what I should have as the formula? I've tried:

Today() - produced an error
{{Today()}} - rendering does not work

Thanks so much!
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Ryan,
All I have for my formula is TODAY(). Are you using the formula on a Ui-Only field? Make sure the Formula Return Type for the field is "Date". Also, have you tried using all caps in the formula (TODAY(), not Today())?

If you're still getting an error, do you mind letting me know what kind of error you're getting on Today()?

Thanks!
Emily