Implementing Time-Based Greeting Messages in Mendix

0
m working on implementing a greeting message in my Mendix application based on the current time of day. I want to display 'Good morning' if it's before noon, 'Good afternoon' if it's between noon and 6 PM, and 'Good evening' for the rest of the day. How can I achieve this using Mendix in decision activity?  
asked
2 answers
1

Because the value does not have to be stored, I would recommend using a non persitable entity (called Message) where you add a String attribute called MessageText.

On the homepage (or in the layout) you want to add a dataview based on a DataSource microflow. In the microflow you can retrieve the current account for the current user and create a integer Variable. In the Variable you want to capture the hour portion of the currentdatetime. For this you need to use two parse functions to achieve this. See this example and this and it would be something like parseInteger(formatDateTime([%CurrentDateTime%],'HH')).

Next activity would be to Create the Message object and set the Message Text with an if then else statement like if $Variable < 12 then 'Good morning '+$Account/FullName else if $Variable < 18 then 'Good afternoon '+$Account/FullName else 'Good evening '+$Account/FullName

The Message object will be the output of you microflow.

Hope this will point you in the right direction

 

answered
0

Hey! 

 

I was looking for a similar solution and thought I'd give Micha Friede's solution a try. Works like a charm.

Unfortunately, in our current app we are not allowed to use Datasource Microflows (DS) on the pages. So... I started tinkering and ended up with a solution that doesn't require a persistent entity or DS, just a simple piece of Text.

 

What I did:

1. Added a Text widget to the modeler

2. Then selected 'Edit Caption'

3. In the Edit Parameter popup I entered a version of Micha Friede's code:

 

if parseInteger(formatDateTime([%CurrentDateTime%],'HH')) < 12 then 'Good Morning' else if parseInteger(formatDateTime([%CurrentDateTime%],'HH')) < 18 then 'Good Afternoon' else 'Good Evening'

 

conditional-text-basedontime.png

 

I'm not using the User name in this example btw. It's available as a parameter on my page, however, this could be fixed with a simple Account Xpath retrieve if necessary (but hey, no DS's for me this time haha ;) )

 

Then just press ok a few times and bam! You got yourselves some conditional text ;).

 

Hope it helps some folks!

answered