A take on getMyApprovals() - How to create UI Action / Related List to getUserApprovals() on the User record?

packy
Tera Contributor

Hello everyone,

I added several related lists to the User record to give users pertinent info, My Incidents, My Requests etc. One of which was Approvals Needed but I discovered this only shows the approvals where the User = Approver. I want functionality similar to getMyApprovals, as in the records are not only where the User = Approver but also the approvals for whom the user is an active delegate. I can't use getMyApprovals because that will show the logged in user's approvals, regardless of which User record the person is on.

I tried to create a new Relationship but failed. I then looked at adding a Related Links UI Action but I am struggling. Any assistance to achieve the ultimate goal would be greatly appreciated!

1 ACCEPTED SOLUTION

Brad,



I used your idea to create a Script Include and then a new Relationship to use in a new filter. Thank you!



Script Include:



var UserApprovals = Class.create();


UserApprovals.prototype = Object.extendsObject(AbstractAjaxProcessor, {


Initialize : function() {


},



getUserApprovals : function() {


  //get the user record sys id


  var u = parent.sys_id;


  var answer = new Array();


  var i = 0;


  answer[i++] = new String(u);


  var g = new GlideRecord("sys_user_delegate");


  g.addQuery("delegate", u);


  //make sure the user is supposed to received approvals


  g.addQuery("approvals", "true");


  //make sure the user is an active delegatee


  g.addQuery("starts", "<=", gs.daysAgo(0));


  g.addQuery("ends", ">=", gs.daysAgo(0));


  g.query();


  while( g.next())


    answer[i++] = new String(g.user);


  return answer;


}});



Relationship:



(function refineQuery(current, parent) {


var all = new UserApprovals();


var apr = all.getUserApprovals();


current.addQuery('approver', apr);


current.addQuery('state', "requested");


})(current, parent);



Filter:


find_real_file.png


View solution in original post

2 REPLIES 2

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I would take a look at the getMyApprovals global business rule, then use that to write a new script include where you can pass the sys_id of the user rather than grabbing the logged in user. You can then call the script include in the filter or use a dynamic filter in your related list.



Create a dynamic filter option


Brad,



I used your idea to create a Script Include and then a new Relationship to use in a new filter. Thank you!



Script Include:



var UserApprovals = Class.create();


UserApprovals.prototype = Object.extendsObject(AbstractAjaxProcessor, {


Initialize : function() {


},



getUserApprovals : function() {


  //get the user record sys id


  var u = parent.sys_id;


  var answer = new Array();


  var i = 0;


  answer[i++] = new String(u);


  var g = new GlideRecord("sys_user_delegate");


  g.addQuery("delegate", u);


  //make sure the user is supposed to received approvals


  g.addQuery("approvals", "true");


  //make sure the user is an active delegatee


  g.addQuery("starts", "<=", gs.daysAgo(0));


  g.addQuery("ends", ">=", gs.daysAgo(0));


  g.query();


  while( g.next())


    answer[i++] = new String(g.user);


  return answer;


}});



Relationship:



(function refineQuery(current, parent) {


var all = new UserApprovals();


var apr = all.getUserApprovals();


current.addQuery('approver', apr);


current.addQuery('state', "requested");


})(current, parent);



Filter:


find_real_file.png