How to make chat available based on the time in schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2014 03:44 AM
Hi All,
I am new to service-now, I have a doubt. I need to make the chat button available for the customer between specific time based on the time mentioned in schedule like"5|Mo-Fr 0730-1800|IN" how to do that.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2015 06:07 AM
I used a GlideAjax call to check if the chat is available according to the schedule and then returned the needed values for opening the chat to the client.
Note 1: using the group of the chat queue record is not necessary, you can find your own way of querying the correct record
Note 2: constructing the ajax response was done in another function
/**
* Checks if the current time is in the schedule of the current assignment group's chat queue.
*
* @param group_id Group sys_id.
* @return Chat queue sys_id and name
*/
checkChatQueueSchedule : function (group_id) {
var queue_info_arr = [];
var queue = new GlideRecord('chat_queue');
queue.addQuery('assignment_group', group_id.toString());
queue.query();
//Query chat queue records with the specified group id
if(queue.next()) {
//Grap the schedule id from the chat queue
var queue_schedule = queue.schedule.sys_id.toString();
//Make a new schedule
var schedule = new GlideSchedule(queue_schedule);
//Construct a new glidedatetime object with the current time
var dt = new GlideDateTime();
dt.setDisplayValue(gs.nowDateTime());
//Check, if the datetime is in the given schedule
if(schedule.isInSchedule(dt)) {
//Return queue id and name
queue_info_arr.push(queue.sys_id.toString());
queue_info_arr.push(queue.name.toString());
return queue_info_arr;
}
else {
return "";
}
}
else {
return "";
}
},
Then in the client you can do your normal ajax handling magic and then with the help of jQuery.
Note 3: construct the ajax call as you would in any other place and place the code below into the response handling callback function
Note 4: give the chat action/button/other element an id...helps a bit
Note 5: remember to set "style = display: none;" for the chat element, so by default it is not shown
//Grap the values from the ajax response
var chat_queue_id = group_values[0].getAttribute("value");
var chat_queue_name = group_values[0].getAttribute("display");
if(chat_queue_id != "" && chat_queue_name != "") {
//With jQuery grap the "chat button" element
var chat_btn = jQuery("#chat_element_id");
//Give it a onclick function with the correct queue id and name
chat_btn.click(function(){
CustomEvent.fire(LiveEvents.LIVE_EVENT, LiveEvents.LIVE_WINDOW_JOIN_QUEUE_QUERY, chat_queue_id, chat_queue_name); return false;
});
//Set the button visible
chat_btn.show();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2014 04:36 AM
Create a script include to do that validation (GlideSystem - ServiceNow Wiki will help you), make it client callable, so you call the script on the conditions of the button (UI Action), add the condition javascript:yourFunction(), and that's it.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2015 04:10 AM
HI Jani Luostarinen , Riyas Ahamed
I have been tasked to change the color of the chat in red when it is not in the schedule business period and green when it is.
Have you achieved to complete your task ? If yes, Could you provide me further information please ? (I am beginner, Screenshots will be helpful )
Where exactly Should I paste the script above ? Can you give me more details please ?
I already have the schedule and I am getting the same message than solutioner now 's in his post.
I look forward to your reply, Thank you very much.
Kind regards,
ZA