Show pending Approval Items for running User or any Groups that the user is a part of

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I am trying to show pending Approval Items for the running User, but in Salesforce, Approvals can be assigned to a User or to a Group that the user is a member of.

To make it more complex, Groups can be members of other Groups, so, say that the Approval Item is assigned to East Coast Sales, which has child Groups, Southeast Sales and Northeast Sales, and the User is a member of Southeast Sales, then this Approval Item should show up as well.

Or if the Approval is for a Group that the User is a member of via the User's Role (since Roles can be members of Groups), this should show up as well.

I tried using a "Result of Subquery" Condition with Subcondition Logic that includes OR statements, such as "1 OR 2 OR 3 OR 4", but OR logic is not allowed on Semi-Join Subselect queries.

Can this be set up using Skuid Models?
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
This can be done by querying separately for the User's Groups, the User's Role Groups, the Groups that the User's Groups are a member of, and the Groups that the User's Role Groups are a member of --- and then using 4 "Field from another Model" IN Conditions on your Approval Items (ProcessInstanceStep) combined with OR Condition Logic.

Here is a Gist containing the XML for a starter Skuid page that will enable this.


Here is a screenshot of the Conditions for each of the 5 Models required:

 












(Edited)
Photo of Bridget Dubas

Bridget Dubas

  • 212 Points 100 badge 2x thumb
Hi Zach,
I copied in this XML and when I tested I was seeing more Pending Approval records than I had in my standard Home Page "Items to Approve".  What I saw was that this list showed items that were pending approval that I had submitted but that were not pending my approval.  Was that the intention?  I would only want to see the items that logged in User needed to approve.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Bridget, I think that the intention was to show items that the logged in User needed to approve, or items that need to be approved by a member of a Group or Role that the User is a part of / assigned to.  My understanding of the ProcessInstanceStep object, coming from the API doc, is that the "ActorId" field describes exactly what you're looking for --- the User who is currently needing to approve an item. I may be missing something here, but from what I can tell, the Model setup described above should be doing what you're after, but it may contain some extra data in the case that there are Approvals assigned to Public Groups or Roles that you're a part of.
Photo of Bridget Dubas

Bridget Dubas

  • 212 Points 100 badge 2x thumb
Thanks for the response Zach.  How could I skinny it down to just be the records that were pending the logged in Users approval?
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
If that's all you're after, you can probably delete the first 4 Models, and on the PendingApprovalItems Model, do the following:

1. remove the Condition Logic
2. Remove Conditions 3-6, so that only the following are left:

1. ProcessInstance.Status = "Pending"
2. ActorId = (Userinfo) User Id