- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 11:25 AM
I have a requirement where if the Organizational type is division then the manager will be the approver of the change if the organizational
type is not division then it should check the parent group , it should continue until the organizational type is division and then the manager of that group should be approver of the change
Can some one help me with the script
In this example first it will check the assignment group and see if the type is division or not if not it should check for the parent in that group and see for the organizational type ,,
I am stuck with the scripting part in the approval user activity in workflow
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 11:09 AM
This fixed my issue after making some changes
var manager = groupOrg(current.assignment_group);
answer = [];
answer.push(manager);
function groupOrg(groupObj){
if(groupObj.u_organizational_type == 'division'){
return groupObj.manager.toString();
}
else if(groupObj.parent != '') {
return groupOrg(groupObj.parent);
}
return;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 02:08 PM
Please update gr.manager line to
return gr.manager.toString();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 01:51 PM
Try the below if you would like to send approval to all the parent groups with Org type as division
answer = groupOrg(current.assignment_group);
var managers= [];
function groupOrg(id){
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', id);
gr.addActiveQuery();
gr.query();
while(gr.next()){
if(gr.u_organizational_type == 'division'){
managers.push(gr.manager.toString());
}
if(gr.parent != '')
groupOrg(gr.parent);
}
return managers
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 01:23 PM
Here's a robust way of going through groups to find the right one:
answer = findApprovingManager();
function findApprovingManager() {
if (current.assignment_group.u_organizational_type == 'division') {
answer.push(current.assignment_group.manager.toString()); // Base Case
} else {
answer.push(grabHierarchy(current.assignment_group.parent.toString()));
}
return answer;
}
function grabManager(selectedGrp) {
var result = [];
var divGrp = new GlideRecord('sys_user_group');
divGrp.addQuery('sys_id', selectedGrp.toString());
divGrp.addQuery('u_organizational_type', 'division');
divGrp.addActiveQuery();
divGrp.query();
if (!divGrp.next()) {
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', selectedGrp.toString());
gr.query();
if (gr.next()) {
var nextGrp = gr.parent;
grabManager(nextGrp);
}
} else {
result.push(divGrp.manager);
}
return result;
}
Let me know if this answers your question by marking it as correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 01:33 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 02:03 PM
Try the below code, I believe I figured out what might be causing the issue.
Are you adding anything additional to this approval script, beyond what I have provided?
answer = findApprovingManager();
function findApprovingManager() {
if (current.assignment_group.u_organizational_type == 'division') {
answer.push(current.assignment_group.manager.toString()); // Base Case
} else {
answer.push(grabManager(current.assignment_group.parent.toString()));
}
return answer;
}
function grabManager(selectedGrp) {
var result;
var divGrp = new GlideRecord('sys_user_group');
divGrp.addQuery('sys_id', selectedGrp.toString());
divGrp.addQuery('u_organizational_type', 'division');
divGrp.addActiveQuery();
divGrp.query();
if (!divGrp.next()) {
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', selectedGrp.toString());
gr.query();
if (gr.next()) {
var nextGrp = gr.parent;
grabManager(nextGrp);
}
} else {
result = divGrp.manager.toString();
}
return result;
}