- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 10:28 AM
HI
I have a user defined field on my sys_user table. The field is called VP. I need to populate this field with the VP names for all my users. I do have VP or Vice President in the title field in sys user. Does anyone have any ideas how I can populate the VP field for my users? The VP could be 5 or 7 layers deep when dot walking to the user.manager.manager.manager etc
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2018 05:01 AM
HI
Thanks for your help I got the below code to work
(function executeRule(current, previous /*null when async*/)
{
var manager_sys_id=current.sys_id;
var managertitle = current.title;
var managerid=current.sys_id;
gs.addInfoMessage('++++user sysid is: ' + manager_sys_id);
gs.addInfoMessage('++++user title is: ' + managertitle);
gs.addInfoMessage('++++user managerid is: ' + managerid);
findVP(manager_sys_id);
function findVP(manager_sys_id)
{
var user = new GlideRecord('sys_user');
user.get(manager_sys_id);
gs.addInfoMessage('++++Manager found is++++'+user.name+'+++++with title+++'+user.title + '++++++user id :' + user.sys_id + 'indexof :' +user.title.indexOf('VP'));
if (user.title.indexOf('VP')==-1)
// gs.addInfoMessage('++++ENTER VP CODE ++++' + '++++++user id :' + user.sys_id);
findVP(user.manager);
if (user.title.indexOf('VP')==0)
{
gs.addInfoMessage('++++enter the name of VP++++' + user.name);
current.u_vp_name=user.name;
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 01:26 PM
Try below script and add it as onbefore BR
current.u_vp_name = findVP(current.manager); ///my exact field name is u_vp_name
function findVP(manager_sys_id)
{
var user = new GlideRecord('sys_user');
user.get(manager_sys_id);
if (user.title.indexOf('VP')==-1)
{
findVP(user.manager);
}
else
{
return(user.sys_id);
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 05:07 AM
thanks removed the existing code and add the above as an before insert, update, query BR and still did not work any other ideas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 10:02 AM
XCool.....Lets add some debug statement. Can you confirm, you have this BR on sys_user taboe and it is a before update BR
current.u_vp_name = findVP(current.manager); ///my exact field name is u_vp_name
function findVP(manager_sys_id)
{
gs.addInfoMessage('++++inside VP++++');
var user = new GlideRecord('sys_user');
user.get(manager_sys_id);
gs.addInfoMessage('++++Manager found is++++'+user.name+'+++++with title+++'+user.title);
if (user.title.indexOf('VP')==-1)
{
findVP(user.manager);
}
else
{
return(user.sys_id);
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2018 07:57 AM
yes BR is before on insert, update or query on Sys_user table
here is the debug
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2018 09:19 AM
so I got this code to work however, the current.u_vp_name is setting to the first manager that is return not the vp name that is return any ideas on how to fix that?
(function executeRule(current, previous /*null when async*/) {
var manager_sys_id=gs.getUserID();
gs.addInfoMessage('++++user sysid P++++' + manager_sys_id);
findVP(manager_sys_id);
function findVP(manager_sys_id)
{
var user = new GlideRecord('sys_user');
user.get(manager_sys_id);
gs.addInfoMessage('++++Manager found is++++'+user.name+'+++++with title+++'+user.title);
if (user.title.indexOf('VP')==-1)
{
findVP(user.manager);
gs.addInfoMessage('++++VPPPPPP found is++++'+user.name+'+++++with title+++'+user.title);
current.u_vp_name=findVP(user.manager.name);
gs.addInfoMessage('++++++++'+user.manager.name+'+++++with title+++'+user.title);
}
else
{
return(user.sys_id);
}
}
})(current, previous);