Business Hour for Virtual Agent

RRolling
Tera Guru

Hello,

I'm looking far a solution to a request that came up. I'm looking to create some type of "Business hour" greeting for VA. Something where if the current time is outside of 7am-5pm a greeting would let the users know that no IT is staffed and that a ticket may sit unassigned until the next morning. If inside those hours it just goes about its normal greeting.

Has someone done this before? can this be done with a Script Action and Decision on the greeting flow in Designer?

 

Thanks for any advise,

Robert 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@RRolling 

create your own Topic for greetings and add it in the Configuration record.

check the current date/time of user's locale and if it falls outside then show message

1) Create new topic

find_real_file.png

find_real_file.png

2) Script: Use Text Bot Response and add script in Response message

find_real_file.png

(function execute() {

	var gdt = new GlideDateTime();
	var message;
	var localTime = gdt.getDisplayValue().toString().split(' ')[1];

	var hour = localTime.split(':')[0];
	if(hour > 17 || hour < 7){
		message = 'no IT is staffed and that a ticket may sit unassigned until the next morning';
	}
	else{
		// your normal greeting message
		message = 'Hi ' + [vaInputs.user.name] + ', my name is Chatbot and I am your virtual agent. How can I help you today?';
	}
	return gs.getMessage(message);

})()

find_real_file.png

find_real_file.png

3) Publish that topic and then link it here under Custom Greetings and Setup module record

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@RRolling 

create your own Topic for greetings and add it in the Configuration record.

check the current date/time of user's locale and if it falls outside then show message

1) Create new topic

find_real_file.png

find_real_file.png

2) Script: Use Text Bot Response and add script in Response message

find_real_file.png

(function execute() {

	var gdt = new GlideDateTime();
	var message;
	var localTime = gdt.getDisplayValue().toString().split(' ')[1];

	var hour = localTime.split(':')[0];
	if(hour > 17 || hour < 7){
		message = 'no IT is staffed and that a ticket may sit unassigned until the next morning';
	}
	else{
		// your normal greeting message
		message = 'Hi ' + [vaInputs.user.name] + ', my name is Chatbot and I am your virtual agent. How can I help you today?';
	}
	return gs.getMessage(message);

})()

find_real_file.png

find_real_file.png

3) Publish that topic and then link it here under Custom Greetings and Setup module record

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

This was very helpful and I got it working with my greeting. Two new issues I wasn't thinking about is now giving me issues. Timezones and weekends. I'm looking into ways to display the greetings based on timezone or if the day is either Saturday or Sunday.

If you have any pointers let me know. If not, what you gave me has already helped.

Robert

@RRolling 

Glad to know.

Please mark my response as correct and close the thread.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@RRolling 

you can check if it's saturday or sunday like this

var gdt = new GlideDateTime();

var dayOfWeek = gdt.getDayOfWeekLocalTime();

if(dayOfWeek == 6){
	// saturday
}
if(dayOfWeek == 7){
	// sunday
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader