how to set Good Morning/Good afternoon /evening depending on user's login time in ChatBot greetings ?

ankit_sharma487
Kilo Guru

how to set Good Morning/Good afternoon /evening depending on user's login time in ChatBot greetings ?

@Hardit Singh 

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Did a really quick test, works instantly:

find_real_file.png

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

LinkedIn

View solution in original post

16 REPLIES 16

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Nice question!

Would be certainly possible. Have you tried creating your own Greetings topic? Obtaining the users timezone or local time, and depending on certain times a different message through Script?

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

LinkedIn

@Mark Roethof , no , i have not worked on GlideDateTime much, but yes i have created own personalized greetings which populates the topics from tables. Thanks for your help.

Hi Mark,

 

Can we do this requirement in Agent Chat?

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


You can do this using designer. You need to edit the greetings designer and add the code

find_real_file.png

 

find_real_file.png

 

Thanks,
Ashutosh