---
original_url: "https://jace.pro/blog/getting-the-next-n-approvals/"
format: markdown
ai_optimized: true
---

Getting the next N approvals# Getting the next N approvals

September 24, 2018 [servicenow ](/tags/servicenow/)[approvals](/tags/approvals/)

  Enable AI AnimationI was talking with someone they were asking how to get the next x approvals up to 10. You can’t always control the environment you work in. He was trying to get the next x approvals. I came up with this script;

`// start debugging
var current = {};
current.variables = {};
current.variables.user = gs.getUserID();
// end debugging

function getManager(user,display){
  var m = new GlideRecord('sys_user');
  if (m.get(user)) {
    // gs.print(m.manager.getDisplayValue() + ' : ' + m.getValue('manager')); 
    if (display) {
      return m.getDisplayValue('manager');
    } else {
      return m.getValue('manager');
    }
  }
}
var approvals = [];
for (var x=1; x<=10; x++) {
  if (x===1) {
    approvals.push({
        x: x,
        name: getManager(current.variables.user,true),
        sys_id: getManager(current.variables.user,false)
        });
  } else {
    approvals.push({
        x: x,
        name: getManager(approvals[x-2].sys_id,true),
        sys_id: getManager(approvals[x-2].sys_id,false)
    });
  }
  // gs.print('level ' + x + ' ' + approvals[x]);
}

gs.print(JSON.stringify(approvals,'','  '));`
---
[View this page on GitHub](https://github.com/jacebenson/jace.pro/tree/main/./src/posts/2018/2018-09-24-getting-the-next-n-approvals.md).

[Getting the next N approvals](https://jace.pro/blog/getting-the-next-n-approvals/) [Jace Benson](https://jace.pro) ![Jace Benson](https://jace.pro/icon-512x512.png)

---

*This content is from Jace Benson's ServiceNow and tech blog at jace.pro*
*Original post: https://jace.pro/blog/getting-the-next-n-approvals/*
