CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to place a single contact in multiple groups
Pages: [1]

Author Topic: How to place a single contact in multiple groups  (Read 536 times)

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
How to place a single contact in multiple groups
October 14, 2013, 12:47:18 pm
Hi, I know I can use something like:

$params = array(
  'version' => 3,
  'sequential' => 1,
  'contact_id' => 1,
  'group_id' => 2,
);
$result = civicrm_api('GroupContact', 'create', $params);

to add a single contact to a single group (group_id=2).

Is there a method to assign this single contact to multiple groups without having to loop through the previous example.
I tried to put an array but I am getting an error message:

A fatal error was triggered: One of parameters (value: ) is not of the type Integer
--
Nick (aka nant from CB Team)

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
Re: How to place a single contact in multiple groups
October 19, 2013, 02:45:17 am
Guessing that no answer means no such feature exists, so I will just loop through using php.
--
Nick (aka nant from CB Team)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: How to place a single contact in multiple groups
October 20, 2013, 11:45:52 pm
Yes, you would have to loop through your contacts, you can not pass an array with multiple groups. So you'd create a loop getting all groups with the API Group Get, and then adding the contact as you are.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
Re: How to place a single contact in multiple groups
October 21, 2013, 12:11:56 am
Quote from: Erik Hommel on October 20, 2013, 11:45:52 pm
Yes, you would have to loop through your contacts, you can not pass an array with multiple groups. So you'd create a loop getting all groups with the API Group Get, and then adding the contact as you are.

Thank you for responding and clarifying this.
--
Nick (aka nant from CB Team)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to place a single contact in multiple groups

This forum was archived on 2017-11-26.