- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2020 12:41 AM
how to set Good Morning/Good afternoon /evening depending on user's login time in ChatBot greetings ?
Solved! Go to Solution.
- Labels:
-
Virtual Agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2020 12:58 AM
Did a really quick test, works instantly:
Script:
(function execute() {
var gt = new GlideDateTime().getLocalTime().getByFormat('hh');
var answer = 'Hello';
if(gt < 12) {
answer = 'Good morning';
} else if(gt >=12 && gt < 18) {
answer = 'Good afternoon';
} else if(gt >= 18) {
answer = 'Good evening';
}
return answer + ' ' + vaInputs.user.first_name;
})()
Just add this on a Bot Response Text within the Greetings topic you are using.
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
‎06-05-2020 12:47 AM
Hello,
You can customize your message under below property
Welcome message
[com.glide.cs.general.welcome_message] | The text string for the default conversation greeting. |
Navigation path is
Collaboration > Virtual Agent > General Settings.
Mark my ANSWER as CORRECT and HELPFUL if it helps

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2020 12:58 AM
Did a really quick test, works instantly:
Script:
(function execute() {
var gt = new GlideDateTime().getLocalTime().getByFormat('hh');
var answer = 'Hello';
if(gt < 12) {
answer = 'Good morning';
} else if(gt >=12 && gt < 18) {
answer = 'Good afternoon';
} else if(gt >= 18) {
answer = 'Good evening';
}
return answer + ' ' + vaInputs.user.first_name;
})()
Just add this on a Bot Response Text within the Greetings topic you are using.
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
‎06-05-2020 03:03 AM
this worked like charm, perfectly !!!! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2020 06:27 AM
i checked further and found for 24hrs format , because initially it worked for me [i changed diff timezones and it worked and switched saluation Good morning to Afternoon but later it stuck to Good Morning only] , i tweaked only minute part:
so it started giving answer in 24 hours format
var gt = new GlideDateTime().getLocalTime().getDisplayValue();
var answer;
var x = gt.split(':')[0];
if(x < 12) {
answer = 'Good morning';
} else if(x >=12 && x < 18) {
answer = 'Good afternoon';
} else if(x >= 18) {
answer = 'Good evening';
}
//return answer + ' ' + vaInputs.user.first_name;
return gs.getMessage('{0}', answer +' '+ [vaInputs.user.first_name.getDisplayValue(), vaSystem.getGreetingMessage()]);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2020 02:49 PM
Thanks Mark, this works really well.
Just a quick clarification, should I want to have my date format not in the 24 HR format (.getByFormat('hh');), what should I change it to?
(function execute() {
var gt = new GlideDateTime().getLocalTime().getByFormat('hh');
var answer = 'Hello';
if(gt < 12) {
answer = 'Good morning';
} else if(gt >=12 && gt < 18) {
answer = 'Good afternoon';
} else if(gt >= 18) {
answer = 'Good evening';
}
return answer + ' ' + vaInputs.user.first_name;
})()