Where is my isApprovalMine()??

chernyee
Kilo Explorer

I've a function called isApprovalMine() which I want to debug. This function is used in an UI Actions' condition field as below:-

(current.approval == 'requested' || current.approval == 'rejected' || current.approval == 'open' || current.approval == 'pending') && (gs.hasRole('admin') || gs.hasRole('approval_admin') || isApprovalMine(current))


The problem is I am not sure where the function is hiding. 😞

I've searched thru the Script Include, Client Script, Validation Script and Business Rules and even enable Debug All but still no clue where is it.

Hope anybody read this post can help me on this :).

Thanks.

4 REPLIES 4

john_roberts
Mega Guru

It's in a global business rule called 'getMyApprovals'.


Thanks. I found it finally :).


I am looking for a similar function as "isApprovalMine()".



But instead of getting personal approvals from a user I would like to collect group approvals from a certain user.


Any ideas?


I am not fully sure, but it seems that isApprovalMine() is not able to correctly handle records with several approval steps, like Change Request. In my case UI Action Approve Change is shown also for the user, who is not a member of the group, which is currently requested for approval, if the user is asked for approval in earlier steps. Here is my solution, HTH 🙂

 

UI Action: Approve Change

Condition:

isApprover(current) && current.type=='normal'&&(current.state=='-4'||current.state=='-3')

Script:

function approveChg() {
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state', 'requested');
gr.addQuery('sysapproval', current.sys_id);
gr.query();
while (gr.next()) {
if (isApprovalMine(gr)) {
gr.setValue('state', 'approved');
gr.update();
}
}
action.setRedirectURL(current);
}
approveChg();

 

Business Rule: XGetMyApprovals

function isApprover(rc) {
var gr = new GlideRecord('sysapproval_approver');
gr.addActiveQuery();
gr.addQuery('approver', gs.getUserID());
gr.addQuery('document_id', rc.sys_id);
gr.addQuery('state', 'requested');
gr.addQuery('sysapproval', rc.sys_id);
gr.query();
if (gr.next()){
//gs.warn(gr.document_id);
return true;
}
else {
return false;
}
}