- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2014 06:51 AM
Hi All,
I am working on a business rule that can tell the Help Desk analyst know who is working/viewing the incident they click on. We had a few times that multiple analysts were working on the same incident because they didn't know if someone was already working it. They clicked on it at the same time and after they put their work notes, they noticed that it had the other's analysts names on the work notes also. We would like to prevent that from happening, so I am trying to get a message to display at the top of the incident that says "User 'Jane Doe' is viewing this incident" or something like that.
I found a BR by Andrew Venables in the ServiceNow share that is perfect for our needs. The only problem is that when I view the open incidents, it tells me that all the users logged in are viewing it. For example, if I click on Incident #10, it tells me that Analyst1 and Analyst2 are viewing it but they have not opened it. If I click on Incident #11, it tells me the same thing.
What I would like to do is to display the names of the analyst in one incident that is actually clicked on and opened, not all incidents... Do you have any idea how I can get this done? Please advise!!
This is the BR:
getClientTransactions();
function getClientTransactions() {
var transactionGr = new GlideAggregate('syslog_transaction');
transactionGr.addQuery('client_transaction', true);
transactionGr.addQuery('table', current.getTableName());
transactionGr.addQuery('URL', 'STARTSWITH', '/'+current.getTableName()+'.do');
transactionGr.addQuery('URL', 'CONTAINS', current.sys_id);
transactionGr.addEncodedQuery('sys_created_onONLast 1 minutes@javascript:gs.minutesAgoStart(1)@javascript:gs.minutesAgoEnd(0)');
//transactionGr.addQuery('sys_created_on', '>=', gs.minutesAgo(1));
transactionGr.addQuery('sys_created_by', '!=', gs.getUserName());
transactionGr.groupBy('sys_created_by');
transactionGr.addAggregate('MAX', 'sys_created_on');
transactionGr.orderByAggregate('MAX', 'sys_created_on');
transactionGr.query();
if (transactionGr.hasNext()) {
var userGr, user, msg = '', userCount = 0;
while (transactionGr.next()) {
userCount++;
userGr = new GlideRecord('sys_user');
user = transactionGr.sys_created_by;
if (userGr.get('user_name', transactionGr.sys_created_by)) {
user = userGr.getDisplayValue();
}
var nowGdt = new GlideDateTime();
var createdGdt = new GlideDateTime(transactionGr.getAggregate('MAX', 'sys_created_on'));
var dur = GlideDateTime.subtract(createdGdt, nowGdt);
msg += user+' is viewing this record '+dur.getDisplayValue().toLowerCase()+' ago';
}
msg = ' viewed this '+current.getClassDisplayValue()+' in the last minutes:'+msg;
if (userCount == 1) {
msg = 'Another user has'+msg;
} else {
msg = 'Other users have'+msg;
}
gs.addInfoMessage(msg);
}
}
This is what I would like to show on incidents that actually get clicked on by any analyst so others can see it.
This shows on an incident that was not clicked on or opened by any of the mentioned analysts.
This shows that I am viewing the incident, but I did not click on it.
Thank you all for your time and help!
Yeny
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 05:00 AM
Hi Yeni,
I wrote a similar code to above one but using only GlideRecord, check if it satisfies your requirements.
Write the below code in a display business rule on incident table.
/****************************************************************************************************
getClientTransactions();
function getClientTransactions() {
var transactionGr = new GlideRecord('syslog_transaction');
var queryToUse = "urlSTARTSWITH/incident.do^type=form^sys_created_by!="+gs.getUserName()+"^urlLIKEsys_id="+current.sys_id+"^sys_created_onONLast 15 minutes@javascript:gs.minutesAgoStart(15)@javascript:gs.minutesAgoEnd(0)";
transactionGr.addEncodedQuery(queryToUse);
transactionGr.orderBy('sys_created_by');
transactionGr.orderByDesc("sys_created_on");
transactionGr.query();
var previousUser = "", messageToUser = "", allUsers = [];
var nowGdt = new GlideDateTime();
var createdOnGdt, timeSpent;
var userCount = 0;
while (transactionGr.next()) {
if(previousUser != transactionGr.getValue("sys_created_by")) {
previousUser = transactionGr.getValue("sys_created_by");
createdOnGdt = new GlideDateTime(transactionGr.sys_created_on);
timeSpent = GlideDateTime.subtract(createdOnGdt, nowGdt);
allUsers.push(getUserName(transactionGr.getValue("sys_created_by"))+' is viewing this record from '+timeSpent.getDisplayValue().toLowerCase());
userCount++;
}
}
if (allUsers.length != 0) {
gs.addInfoMessage(allUsers.join(","));
}
}
function getUserName(userName) {
var sysUser = new GlideRecord("sys_user");
sysUser.addQuery("user_name", userName);
sysUser.query();
if(sysUser.next()) {
return sysUser.getDisplayValue();
}
return 'guest';
}
******************************************************************************************/
Note that this is specific to incident table, if you have requirements that need you to generalize it, make sure you make the necessary changes.
Thanks,
Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 05:56 AM
Agreed, there's really no good way to report on it without having some performance issues due to the constant updating of a field. I don't have any other method though but what you could try doing is maybe create some sort of UI page to show the incidents being touched but still, I haven't tried it and don't know if it's a good idea either.
Depending on the version that you're in, you could take a look at user presence functionality. You may be able to get something better with that.
https://docs.servicenow.com/bundle/helsinki-platform-user-interface/page/use/navigation/concept/c_UserPresence.html
Yeny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 06:04 AM
I have tried User Presence feature.But unable to find relevant scripts and table for it. So not able to forward into this direction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 06:05 AM
Yeny, just curious, but what is your definition of "Viewing".
How does ServiceNow know that the technician has left the Record in question?
Technically, this BR is ALWAYS going to fire, because chances are some other technician has opened it prior to this technician looking at it, if you're talking about "for all time".
I think the reason that the Simultaneous update is an onSubmit is that it's really the only issue you have. I understand that a technician that may perform a lot of updates on a ticket, then submits it, only to find out that someone else has submitted an update since they opened the record, is an issue; but it's easily solved by just aborting the submit and allowing them to copy/paste/note the changes they made, reload the form, and remake them.
I believe you're going to have an issue with anything that is "viewing", as you're going to have to define somehow the length of time they're allowed to "view" the form before assuming they've left and not providing the pop-up. All ServiceNow can tell you is WHEN they loaded the form, not that they've closed their browser or moved to something else. Logic of the form:
if (anyone_has_ever_opened_form_before_me) {
show infomessage;
}
Will often display the infomessage, even if it was a week ago that someone opened it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 02:01 PM
Hi Rob,
Good point! What I was trying to achieve is that when an analyst clicks and opens an incident, they'll get a message saying that someone is already viewing it so they can move on to the next incident. The analyst is required to assign the incident to themselves when they open it but our call volume is high so it may take a few minutes for them to assign it, so I've set the 'view' time to 5 minutes to allow the other users to see the message for that long. In that time, the analyst that has the incident, should have assigned it to themselves so it will disappear from the queue.
The BR that Mandar provided fixed the issue that I was having before and now it works just like I wanted it to.
Thank you for your input, Rob, and although the onSubmit client script didn't work as I wanted it to at first, I'll be looking into it more to make it work for our needs.
Thank you,
Yeny.
