4

I have a max no of users limit for a group, so whenever someone adds a groupContact using the civicrm dashboard, I would like to present them with an error which prevents adding a new group and stating a message for the same.

I am using a civicrm_api() but could not figure out how to prevent the creation of groupcontact or provide a validation for the same?

  • If you explain the purpose of this limit people might suggest other solutions – petednz - fuzion Jun 8 '15 at 19:58
2

Just to be sure: civi doesn't have any limit on the number of contacts per group, it's a business case you have that introduces that constraint, right?

I didn't find a safe way to prevent an operation (I'm not sure it's a good idea, it might introduce lots of problems later on, the best IMO is to fail the query).

One workaround to get that is to introduce an invalid value in the pre hook (eg set contact_id or group_id to null, the query will fail and it will prevent inserting.

2

You can add a form rule to check the number of contacts in the group and if exceeded, display the error message.

You might also be able to do this via js and the api, but that potentially could be circumvented. If you want to ensure this never happens, you should add a post hook on the civicrm_group_contact object and fatally abort if the constraint is violated.

  • This would need to be added for every ui (eg from the contact edit form, from the bulk action add to group, from the group tab...) and still won't prevent (for instance) to mass add them via import... – Xavier Jun 8 '15 at 12:31
  • 1
    If you want to really restrict it, you can add a fatal abort to the post hook on the group contact object, which should be called every time – Donald Lobo Jun 8 '15 at 13:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.