Database view - how to call a function on "where clause" to filter for "My Approvals".

mfhaciahmetoglu
Mega Sage

Hello,

 

I am looking for a solution to add more information on sysapproval_approver table for the associated RITM record.

 

I have done it via database_view. But I also need to filter the view via the active user and the delegated approvals to her or him. The logic should work just as when you enter "Self-Service -> My Approvals" (you see that the page is already filtered for the active user and the delegated approvals).

 

Any idea how I can call this function?

 

Thank you!

 

Best,

Firat

1 ACCEPTED SOLUTION

mfhaciahmetoglu
Mega Sage

 

Hi @Brad Bowman ,

 

Thanks a lot for your help.

 

Your code did not work for me but when I modified it a bit, it worked just fine:

 

 

 

(function executeRule(current, previous /*null when async*/) {
	//gs.info('delegated one =' + new ApprovalDelegationUtil().getOnlyDelegatedApprovals());
    gs.info('approvers =' + new ApprovalDelegationUtil().getApprovers());
	// Get delegated approvals and approvers
    //var delegatedApprovals = new ApprovalDelegationUtil().getOnlyDelegatedApprovals();
    var approvers = new ApprovalDelegationUtil().getApprovers();
 	current.addQuery('app_approver', 'IN', approvers);
})(current, previous);

 

 

 
//gs.info('delegated one =' + new ApprovalDelegationUtil().getOnlyDelegatedApprovals());
This one always returned null.
 
However, the other one had everything that is delegated to me and my own approvals. So, it was sufficient to use that.
Thanks for help again.
 
Best,
Firat

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

You can further filter a Database View using a before Query Business Rule with the Database View Name as the Table. You need to prefix field names with the Variable prefix used in the view, so if you are using the sysapproval_approver table with a prefix of app, then the BR script to mirror the My Approvals view would be

(function executeRule(current, previous /*null when async*/) {
	current.addEncodedQuery('app_sys_id=' + new ApprovalDelegationUtil().getOnlyDelegatedApprovals() + '^ORapp_approver=' + new ApprovalDelegationUtil().getApprovers());
})(current, previous);

 

mfhaciahmetoglu
Mega Sage

 

Hi @Brad Bowman ,

 

Thanks a lot for your help.

 

Your code did not work for me but when I modified it a bit, it worked just fine:

 

 

 

(function executeRule(current, previous /*null when async*/) {
	//gs.info('delegated one =' + new ApprovalDelegationUtil().getOnlyDelegatedApprovals());
    gs.info('approvers =' + new ApprovalDelegationUtil().getApprovers());
	// Get delegated approvals and approvers
    //var delegatedApprovals = new ApprovalDelegationUtil().getOnlyDelegatedApprovals();
    var approvers = new ApprovalDelegationUtil().getApprovers();
 	current.addQuery('app_approver', 'IN', approvers);
})(current, previous);

 

 

 
//gs.info('delegated one =' + new ApprovalDelegationUtil().getOnlyDelegatedApprovals());
This one always returned null.
 
However, the other one had everything that is delegated to me and my own approvals. So, it was sufficient to use that.
Thanks for help again.
 
Best,
Firat