- 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-15-2020 10:27 PM
Hi there,
So if your format is not in 24h, how does it look then? Does it have AM or PM added? Then you could use that obviously.
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-15-2020 11:04 PM
Yes, it does have AM/PM
Thanks Mark for the response, I have managed to get a work around which is to use the ......"getHourOfDayLocalTime();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 11:19 PM - edited 07-20-2023 11:19 PM
Thanks for this it was helpful.
I had to change the code to HH to return 24 hour format.
//Changed to capital HH to return 24 hour format
var gt = new GlideDateTime().getLocalTime().getByFormat('HH');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2021 05:34 AM
Hello Mark,
I have a requirement like VA using in all locations like India,china,US, UK each and every location time format is not same in that case based on the user location how can we set up greetings based on time?
is there any idea please advice
responses highly appreciated thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2021 05:37 AM
Hi there,
Have you tried what's mentioned in this topic already? It does use getLocalTime.
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