
- 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
ā07-20-2020 03:07 AM
Hi there,
We are using below code on our Virtual Agent. Instead of the return, use your c.data.greeting. And instead of vaInputs.user.first_name use your scope.user.first_name. I think this could work already.
var greetingStr = gs.getMessage('G\'day');
var hourInt = new GlideDateTime().getLocalTime().toString().split(' ')[1].split(':')[0];
if(hourInt < 7) {
greetingStr = gs.getMessage('Good night');
} else if(hourInt >= 7 && hourInt < 12) {
greetingStr = gs.getMessage('Good morning');
} else if(hourInt >= 12 && hourInt < 18) {
greetingStr = gs.getMessage('Good afternoon');
} else if(hourInt >= 18) {
greetingStr = gs.getMessage('Good evening');
}
return greetingStr + ' ' + vaInputs.user.first_name + '!';
If my answer helped you in any way, please then mark it as helpful.
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 03:20 AM
That's fantastic - Thank you Mark - I will try this now š
- 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
ā07-20-2020 05:07 AM
A minor correction on the first if condition is needed, should be an || -
if(hour > 20 || hour <= 4) {
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)