Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

eric_szonyi
ServiceNow Employee

I was trying to configure a few custom chat actions but outside but had some challenges finding documentation on the methods available to the g_chat object. I decided to use standard Javascript to enumerate the methods in the g_form object to see what was available to use. I placed the following in my Chat Action - Onclick Action Script:


var x;
for (var str in g_chat) {
//x += str + ': ' + g_chat.getProperty(str);
if(str.startsWith('get')) { x+= str + '\n' + g_chat[str] + '\n\n'; }
}
alert(x);


So from here it gave me all of the 'get' methods and the functions behind them so I would also know what methods had arguments. This is a useful approach for enumerating JavaScript objects when they are not full documented. Here is the output for reference:


getOffset
function () {
return this.box.getOffset();
}

getWidth
function () {
return this.box.getWidth();
}

getHeight
function () {
return this.box.getHeight();
}

getMessageType
function () {
return this.getType() == LiveGUI.WINDOW_CONVERSATION ? LiveGUI.MESSAGE_TYPE_CHAT : LiveGUI.MESSAGE_TYPE_MUC;
}

getThreadID
function () {
return this.getProperty(LiveGUI.WIN_PROP_THREAD_ID) || '';
}

getUser
function (userJID) {
var i = this._users.length;
var user;
while (i--) {
user = this._users<i>;
if (user.jid.toBareJID() == userJID.toBareJID())
return user;
}
return null;
}

getActiveUsers
function () {
return this._getSortedUsersByStatus(this.STATUS_ACTIVE);
}

getInvitedUsers
function () {
return this._getSortedUsersByStatus(this.STATUS_INVITED);
}

getConversationUserJID
function () {
return this._users[1] ? this._users[1].jid : null;
}

getChatType
function () {
if (this.getType() == LiveGUI.WINDOW_CONVERSATION) {
return LiveGUI.MESSAGE_TYPE_CHAT;
}
else if (this.getProperty(LiveGUI.WIN_PROP_QUEUE_JID)) {
var jid = new JID(this.getProperty(LiveGUI.WIN_PROP_CHAT_QUEUE_USER));
if (LiveMux.get().getUserJID().equals(jid))
return LiveGUI.TYPE_QUEUE_USER;
jid = new JID(this.getProperty(LiveGUI.WIN_PROP_CHAT_QUEUE_AGENT));
if (LiveMux.get().getUserJID().equals(jid))
return LiveGUI.TYPE_QUEUE_AGENT;
}
return LiveGUI.MESSAGE_TYPE_MUC;
}

getChatQueueUser
function () {
var bareJID = this.getProperty(LiveGUI.WIN_PROP_CHAT_QUEUE_USER);
return bareJID ? new JID(bareJID).getID() : '';
}

getChatQueueAgent
function () {
var bareJID = this.getProperty(LiveGUI.WIN_PROP_CHAT_QUEUE_AGENT);
return bareJID ? new JID(bareJID).getID() : '';
}

getView
function () {
return this.options.view;
}

getCreationDate
function () {
return this.options.creationDate;
}

getInternalId
function () {
return this.options.internalId;
}

getWindowJID
function () {
return this.options.windowJID;
}

getChannelJID
function () {
return this.options.channelJID;
}

getType
function () {
return this.options.type;
}

getProperty
function (k) {
return this.options.dataProps[k];
}

getProperties
function () {
return this.options.dataProps;
}

getDisplayProperty
function (k) {
return this.options.displayProps[k];
}

getDisplayProperties
function () {
return this.options.displayProps;
}

getWindowTitle
function () {
return this.getProperty(LiveGUI.WIN_PROP_TITLE);
}

getWindowIconClass
function () {
return this._windowIconClass;
}
6 Comments
pu
Giga Contributor

This is very helpful, thank you.

We should be launching chat any day but the chat actions are causing some headaches. I assumed they would be more like UI actions and familiar to use but it all seems to be unique to the chat / social tools and a lack of documentation.

The API page really needs updating please ServiceNow :http://wiki.servicenow.com/index.php?title=Adding_Actions_to_the_Chat_Window_Menu#API


deepakvednegi
Giga Contributor

Need ID for cahnnel

Hi

First of all i would like to thank for the information, it is quite helpful.
Now i want the sys_id of the current chat room in which the agent and user are conversating. I am not able to use ChannelId method. Can you guide me how to use this properly??


solutioningnow
Giga Guru

Very helpful and upto the point information Eric Szonyi Thank you very much


justin_drysdale
Mega Guru

How do you know that all of these methods belong to g_chat and not to other objects higher up in the prototype chain?



For some methods it looks obvious, but some others I'm not so sure.


shaveta
Mega Expert

hi Eric...thanks so much for the info. Where exactly did you write this java script code to find all the methods....


I have a doubt if you could help..I am using OOTB create incident from chat action and its working well. But once an incident is created from a chat window i dont see the chat action after that. what if the same user is facing more than one issues and another incident needs to be logged from the same chat window.


Also could you tell me how this function works:


g_chat.getProperty('short_description')


s_gayathri
Kilo Contributor

Hi   Eric,


Is there any method for getting chat start time. We have a requirement like get chat start time and calculate chat start time and incident created time. let me know if any one achieve this before.