How can a script adding users to the watcher list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 03:45 PM
Good day all,
I am looking for a bit of advice/help with a script as I am pretty clueless with scripting; here is some context for what I am after:
We are using Service Now in a multi-tenanted environment where our customers are a range of different organisation with a number of users in them who use the self service portal to log incidents and interact with us.
In this scenario, all users within an organisation are separate and can only see their own incident records. Most of our organisations include a number of users who work together and need to be able to collaborate on Incident records. Service Now has the concept of watchers which would do the trick however I cannot make that function available to customer users as they can potentially lookup all of our users across all organisations which is something that we can't have happen.
What I would like to achieve if have a boolean field in the user records that determines whether that user wants to see all tickets across the organisation or not. If they chose to see it all, I would like a business rule to add all those users to the watcher list upon the creation of the incident.
Setting this up is pretty straightforward up to the point of the script bit which would have to lookup the users assigned to the organisation that have that flag active and then add them to the watcher list.
Has anyone done something like this or maybe has an easy alternative i have not thought about and could share their ideas?
Many thanks in Advance!
Colin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 05:41 PM
Hi Colin,
Rather than scripting a way to update an enormous number of records with a possibly large group of userIDs, I think you should look into Subscription Based Notifications.
Using Subscription Based Notifications - ServiceNow Wiki
Subscription Based Notifications - ServiceNow Wiki
Email Notifications - ServiceNow Wiki
Setting Up Subscription Based Notifications - ServiceNow Wiki
Subscribable, mandatory and force delivery options on Notifications
Basically, you would make those notifications ("Incident Created", "Incident Commented", "Incident Resolved",etc.) "Subscribable", and then users can opt-in to receive that type of message whenever it gets generated. To manage their subscriptions, a user can click on their name at the top-left to view their profile, and then the link "Notification Preferences".
Hope that helps,
-Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2016 12:38 PM
Hi Colin,
I guess you don't want users from one domain see user records of other domains/companies.
You can still use the watch list field (watch_list) with a reference qualifier on it.
You could use a reference qualifier to show users belonging to current user's domain only.
'Domain'-'is'-'javascript:gs.getUser().getDomainID();'
or
May be the users belonging to domain of the incident ticket only should be listed
'Domain'-'is'-'javascript:current.sys_domain;'
Normally in an MSP instance, users from one domain shouldn't see users of other domain.
But this is a quick work around, though you would need ACLs to have better server side security.
But, if you want users from a domain or company to see an incident record present in some other different domain?
Then its better to move such users (who work together) one level up in domain to some sort of "Global" domain. This is with respect to good practice of an MSP servicenow instance and will allow them to see users from more than one domain under them.
So like you said, when the user selects such flag? his user profile should be updated to some sort of "Global" instance
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2016 04:24 PM
Good day Brian, Maheshwar,
Thank you both for your suggestions; I have played around with both of your suggestions and come to some new conclusions.
First off Brian, I never had really looked at subscriptions and your suggestions has prompted me to look at them a bit closer and yes indeed I can use those in what I am trying to achieve but as a second stage.
Maheshwar, you suggestions is valid too. we don't have the MSP version but we segregate the users based on their company belonging rather then domain.
Our instance supports roughly 100 customer accounts each of which have 4 to 5 users so the number of users I am looking at are not great.
When a user logs onto their self service portal the requestor and the company are populated automatically. what I have now tried to do is have a tick box a customer could select to make their ticket visible to the other users. I have then unsuccessfully tried to write a client script that would, on submit, capture the company and retried the list of users that exist in the same company and add them to a watch list.
Your suggestion Maheshwar was in the right direction but I have actually thought that I could remove the user interaction and make it an all or none scenario that we could control through a tick box which would then minimise the possibility for someone to tinker with it.
If anyone has any hints as to how to formulate that script that would be fantastic.
Many thanks.
Colin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2016 05:22 PM
Hi Colin,
If I understand correctly... when someone creates a new INC, you're going populate the list with all users in the same company that have opted-in to watching all tickets entered for that company.
If that's the case, I would use a BR and not a client-script to populate the list. Since it sounds like they won't/shouldn't be seeing the actual list anyhow, it would be much simpler to populate the list with a Before-insert business rule on [incident], which won't require any additional server calls to setup the information. This example assumes you've added a true/false field to [sys_user] called "u_opt_in_notify":
When: Before (Insert)
//Get all company users who have opted-in to receive such notices
var addUsers = new GlideRecord('sys_user');
addUsers.addQuery('u_opt_in_notify=true^company=' + gs.getUser().getCompanyID());
addUsers.query();
//Build the watch list as a comma separated string of sys_ids
var watchList = "";
var sep = "";
while(addUsers.next()){
watchList += sep + addUsers.sys_id;
sep = ",";
}
//Populate the watch list on the current INC record
current.watch_list = watchList;
That should work for you. However it won't add new users to the watch lists on existing tickets... it would take another separate BR on [sys_user] if you wanted that to happen, but you get the idea.
-Brian