How to execute worfklow per operation?

Hello

 

My goal is to limit the number of members added to a group, for example: I have a group with 4 members, and I set a limitation value of 5 (the value is set in extension attribute 1)

I created a workflow with the operation: “add member to group” and set to run a script function “onPreModify”

 

The script simply checks if $group_count -greater or equal then $group_limit and throw an error if the limit is reached.  

When adding *ONE* user to a group the workflow executed and the script and successfully stopping the user from adding the user

But if I'm adding multiple users at once, the workflow executes the script only one time ,causing the user to bypass the limitation because the script validation process runs only once.

 

Is there any way to make the workflow run for every added user?

Help appreciated, 

Thanks