UI Action condition to show button when user is delegate of assigned to

Jeff Krueger1
Tera Expert

I am trying to show an "Implement" UI Action button on a Change request to either an admin, the user that is the current assigned to, or a user who is the delegate of the current assigned to.   I tried using the getMyAssignments() function from the getMyApprovals business rule, but I'm not able to get it to work properly.   What do I need to add to this condition statement to allow for delegates to see/invoke the button:

(gs.hasRole('admin') || current.assigned_to == gs.getUserID())

1 ACCEPTED SOLUTION

The following changes ended up with a workable solution!   Here is the UI Action condition: new isDelegate().delegatecheck(current.assigned_to))



Script Include:



var isDelegate = Class.create();


isDelegate.prototype = {


initialize: function() {


},


delegatecheck : function (serOwnrVal){


var grDelegate = new GlideRecord("sys_user_delegate");


grDelegate.addQuery("user", serOwnrVal);


grDelegate.addQuery("delegate", gs.getUserID());


grDelegate.addQuery("assignments", "true");


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


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


grDelegate.query();


{


if(grDelegate.next()){


answer = true;


return answer;


}


else{


answer = false;


return answer;


}


}


},


type: 'isDelegate'


};


View solution in original post

13 REPLIES 13

sachin_namjoshi
Kilo Patron
Kilo Patron

You can create a function in a script include and glide record the delegates from sys_user_delegate table using the current user



And in the condition use the above created function.



Regards,


Sachin


I have been working on a script include to query the sys_user_delegate table but I'm not sure how to pass the parameter correctly from the condition:


find_real_file.png


find_real_file.png


I know I must be missing something obvious...


Try adding "new" before "isDelegate"



If that doesn't work, you might want to make a separate method inside the script include.


Please use below function which returns true if person logged in delegate of current assigned to


you can include this function in script include and call this script include in UI action condition



//This function returns true if the person logged is a delegate of current assigned to


isDelegate : function(serOwnrVal) {


var grDelegate = new GlideRecord('sys_user_delegate');


grDelegate.addQuery('user', serOwnrVal );


grDelegate.addQuery('delegate', gs.getUserID());


grDelegate.addQuery('assignments', true);


grDelegate.query();


if(grDelegate.next()){


return true;


}


else{


return false;


}



},



Regards,


Sachin