1
$result = civicrm_api3('Address', 'create', array(
  'sequential' => 1,
  'contact_id' => $householdContact['id'],
  'location_type_id' => "Home",
  'is_primary' => 1,
  'street_address' => $form_state['storage']['contactInfoValues']['address1'],
  'supplemental_address_1' => $form_state['storage']['contactInfoValues']['address2'],
  'city' => $form_state['storage']['contactInfoValues']['city'],
  'state_province_id' =>  $form_state['storage']['contactInfoValues']['state'],
  'country_id' => "US",
));

$master_address_id = $result['id'];



 $result = civicrm_api3('Address', 'create', array(
          'sequential' => 1,
          'contact_id' => $primaryContact['id'],
          'master_id'  => $master_address_id,
          'location_type_id' => "Home",
        ));

I need to attach the household address with primary contact address . How can i achieve I tried by implementing above ,but it did not work?

3

You need to provide same set of values to create address for members of the household with additional parameter master_id as Address foreign key id of household contact.

$addressParams = [
  'sequential' => 1,
  'contact_id' => $householdContact['id'],
  'location_type_id' => "Home",
  'is_primary' => 1,
  'street_address' => $form_state['storage']['contactInfoValues']['address1'],
  'supplemental_address_1' => $form_state['storage']['contactInfoValues']['address2'],
  'city' => $form_state['storage']['contactInfoValues']['city'],
  'state_province_id' =>  $form_state['storage']['contactInfoValues']['state'],
  'country_id' => "US",
];
$result = civicrm_api3('Address', 'create', $addressParams);

$addressParams['master_id'] = $result['id'];
$addressParams['contact_id'] = $primaryContact['id'];
$result = civicrm_api3('Address', 'create', $addressParams);

HTH

Pradeep

| improve this answer | |
  • Hi @pradeep, I just noticed that, we need to have 'is_primary' & 'location_type_id' to link household address to primary contact or any other 2 contacts which needs to be linked, I found this here in the answer given below and link is github.com/civicrm/civicrm-core/blob/… .Also I tried just with master_id and contact_id and it did not work but with is_primary & location_type_id added along with contact_id and master_id it worked! – harshal Jun 5 '18 at 17:07
1

You are currently supposed to add the address details to the address that is sharing the data from another address.

You can see an example here: https://github.com/civicrm/civicrm-core/blob/865168d5d056d071d23d0273189051241c5261e5/tests/phpunit/CRM/Core/BAO/AddressTest.php#L446

Your version should already create a linked address, but does not copy over the data.

It seems only import and API suffer from this issue. The GUI actually does copy over the values. This seems like a usefull feature request.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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