- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 11:29 AM
I am having trouble finding a way to limit a User Reference field to only show managers when selecting a user.
Below are fields on the "sys_user" table that would relate them to a Manager:
****All of the colored out values are user referenced names****
Let me know if this is possible in a simple JavaScript condition statement or if it needs to be done externally from the fields dictionary in a Script Include.
Thank You,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2016 11:41 AM
Here is the solution I have created. It works quite well.
BackfillUser:function(){
var idList = ' ';
var a = current.user;
if(!a){
return;
}
var user = new GlideRecord('sys_user');
user.addQuery('managerISNOTEMPTY');
user.addActiveQuery();
user.query();
while(user.next()){
if(idList.length > 0){
idList += (',' + user.manager.sys_id);
}
else{
idList = user.manager.sys_id;
}
}
return 'sys_idIN' + idList;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 05:23 PM
this seems to be missing the function initialization, can you provide the full script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 08:50 AM
My finished modified version includes a couple more pulls/techniques of pulling others associated with manager.
Script below:
var getUsersByManager = Class.create();
getUsersByManager.prototype = {
initialize: function() {
},
BackfillUser:function(){
var idList = ' ';
//Gets users who are listed as managers of other users
var user = new GlideRecord('sys_user');
user.addQuery('managerISNOTEMPTY');
user.addActiveQuery();
user.query();
while(user.next()){
if(idList.length > 0){
idList += (',' + user.manager.sys_id);
}else{
idList += (',' + user.manager.sys_id);
}
}
//Gets users who are listed as group managers
var group = new GlideRecord('sys_user_group');
group.addQuery('managerISNOTEMPTY');
group.addActiveQuery();
group.query();
while(group.next()){
if(idList.length > 0){
idList += (',' + group.manager.sys_id);
}
else{
idList += (',' + group.manager.sys_id);
}
}
//Gets users who have "Engagement Manager" in their title
var user2 = new GlideRecord('sys_user');
user2.addQuery('titleLIKEEngagement Manager');
user2.addActiveQuery();
user2.query();
while(user2.next()){
if(idList.length > 0){
idList += (',' + user2.sys_id);
}
else{
idList += (',' + user2.sys_id);
}
}
return 'sys_idIN' + idList;
},
type: 'getUsersByManager'
};
//Builds a list and returns the list values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 10:40 AM
hmm... not working when I create a script include and then call it from an advanced ref qual field... doesn't filter down the user list at all
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 11:37 AM
1. Validate the call: javascript: new getUsersByManager().BackfillUser()
2. Make it is on the dictionary of a user referenced variable
3. The code I gave you above was built for the system I was working on, it can be user specific, so comment out each of the query list builders.
For example:
**comment this out, then test**
//Gets users who have "Engagement Manager" in their title
/*
var user2 = new GlideRecord('sys_user');
user2.addQuery('titleLIKEEngagement Manager');
user2.addActiveQuery();
user2.query();
while(user2.next()){
if(idList.length > 0){
idList += (',' + user2.sys_id);
}
else{
idList += (',' + user2.sys_id);
}
}
*/
4. Ensure that if you copy and pasted my code into a script include that you did not keep and repeat the initialiation
5. Validate that the name of your script include matches getUsersByManager
6. Last, ensure that if you copy and pasted my code, values copied are being read by the editor.
For example:
-values inside of "" or '' can sometime not be read by editors
If this still does not solve your problem, let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 11:38 AM
2. Make sure**