
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2020 02:56 AM
Hi all
Currently in our portal we have this personalised greeting when users log in... we used this code
function() {
/* widget controller */
var c = this;
c.data.greeting = 'Hi ' + scope.user.first_name + ',' + ' welcome to your Rathbones IT Service Portal';
}
Question: is it possible change the greeting depending on the time - so if it's pre 12 it would say 'Good morning Richard'
Thanks for you help
Richard
Solved! Go to Solution.
- Labels:
-
Service Desk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2020 03:24 AM
Hi
Since you're generating the greeting message on your widget's client controller, you'd need to use the javascript's date function, unless you want to make a sever side call to get the date-time using the Glide APIs. The javascript Date() will get the date-time from the user's pc.
Here's the snippet to do that:
function() {
/* widget controller */
var c = this;
var today = new Date();
var hour = today.getHours();
var greeting = '';
if(hour > 20 && hour <= 4) {
greeting = greeting + '${Good Night}';
} else if(hour > 4 && hour <= 12) {
greeting = greeting + '${Good Morning}';
} else if(hour > 12 && hour <= 16) {
greeting = greeting + '${Good Afternoon}';
} else if(hour > 16 && hour <= 20) {
greeting = greeting + '${Good Evening}';
}
c.data.greeting = greeting + ', ' + scope.user.first_name + '!' + ' Welcome to your Rathbones IT Service Portal';
}
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-09-2023 04:25 AM
How does your post not have more thumbs up?! This is great stuff.
Thanks for sharing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2024 09:58 AM - edited ā03-19-2024 10:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2020 03:53 AM
That worked perfectly! Thank you so much Rishabh! š š

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2020 03:56 AM
Be aware that that script won't work correctly if the timezones are off, a user has a different timezone, etc..
That's why in my script, I'm using the LocalTime.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2020 04:03 AM
Ah ok - thanks Mark will do š