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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Creating a contact as a copy of another contact
Pages: [1]

Author Topic: Creating a contact as a copy of another contact  (Read 1145 times)

thebeuving

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: Joomla 2.5
  • MySQL version: 5.0.95
  • PHP version: 5.3.3
Creating a contact as a copy of another contact
June 14, 2012, 11:50:45 am
Is it possible to create a new contact as a copy of an existing contact.

Some of the organizations in our CiviCRM setup have Branch offices, I need to create a contact for each Branch but I don't want re-enter all there info when the only real difference is the address.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Creating a contact as a copy of another contact
June 15, 2012, 03:52:33 am
Quote from: thebeuving on June 14, 2012, 11:50:45 am
Is it possible to create a new contact as a copy of an existing contact.

I am not aware of a built-in way. I recently coded such a thing as a Drupal module for a D6 site.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

thebeuving

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: Joomla 2.5
  • MySQL version: 5.0.95
  • PHP version: 5.3.3
Re: Creating a contact as a copy of another contact
June 15, 2012, 09:04:33 am
Unfortunately in this case I am using CiviCRM in Joomla. Would it be possible to look at the code you used for your Drupal module so I can reproduce that in a joomla module/component since the equivalent doesn't seem to exist in joomla?

David

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Creating a contact as a copy of another contact
June 15, 2012, 09:07:47 am
Here you are.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

davyivins

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 2
    • PURCO SA
  • CiviCRM version: 4.5
  • CMS version: Drupal 6.33
  • MySQL version: 5.5.34
  • PHP version: 5.4.33
Re: Creating a contact as a copy of another contact
June 16, 2012, 01:42:51 am
Hi Hershel - this functionality would be very useful for me too. Can I simply install this as a module on my D6 / Civi4.1.2 site or is it more complex than that?
There are times I love technology...and then there are times I *love* technology :-)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Creating a contact as a copy of another contact
June 16, 2012, 01:06:19 pm
Make ld_copy_contact.info with this:

Code: [Select]
name = ld_copy_contact
description = Create a copy of a Contact
package = Other
core = 6.x

and that's it.

This module comes with no guarantee or warranty, neither implied nor implicit, of any kind whatsoever, nor does it come with any support and use of it is at your own risk only.

That said, it should be fine and it's in use on a production site. :)
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

davyivins

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 2
    • PURCO SA
  • CiviCRM version: 4.5
  • CMS version: Drupal 6.33
  • MySQL version: 5.5.34
  • PHP version: 5.4.33
Re: Creating a contact as a copy of another contact
June 17, 2012, 02:58:47 am
Awesome - thank you.  :)
There are times I love technology...and then there are times I *love* technology :-)

davyivins

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 2
    • PURCO SA
  • CiviCRM version: 4.5
  • CMS version: Drupal 6.33
  • MySQL version: 5.5.34
  • PHP version: 5.4.33
Re: Creating a contact as a copy of another contact
June 17, 2012, 06:00:26 am
Hi Hershel - I installed the module and enabled it but can't find where to access the 'copy' function in Civi. What am I missing?

What I did:
- created the .info and .module files
- wrapped them in a folder "ld_copy_contact"
- uploaded the folder to sites/all/modules/CustomCiviModules/
- found and enabled the module in Drupal


There are times I love technology...and then there are times I *love* technology :-)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Creating a contact as a copy of another contact
June 17, 2012, 06:07:59 am
Quote from: davyivins on June 17, 2012, 06:00:26 am
What am I missing?

Oh, I suppose you would like a UI, eh? :)

The built in one is to manually visit ld_copy_contact/contact_id and that does it.

The site using this already had some JS code that put a button like this:

Code: [Select]
var h = ' <input type="hidden" value="0" id="make_history" name="make_history" /> &nbsp; <input type="submit" value="Archive Data Now" onclick="$(\'#make_history\').val(1);" />';
and then some .module code:

Code: [Select]
  if(1 == $_POST['make_history']) {
  module_invoke('ld_copy_contact','copy',$contact_id);
}

in hook_civicrm_postProcess. Something like that.

But if you just visit ld_copy_contact/contact_id that will make a copy.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

davyivins

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 2
    • PURCO SA
  • CiviCRM version: 4.5
  • CMS version: Drupal 6.33
  • MySQL version: 5.5.34
  • PHP version: 5.4.33
Re: Creating a contact as a copy of another contact
June 17, 2012, 06:31:43 am
I'm afraid your generosity in sharing has resulted in a bunch of back and forths - sorry about that !

Visiting ld_copy_contact/contact_id generates the following error:
Call to undefined function civiutils_include() in [...]/ld_copy_contact.module on line 24
There are times I love technology...and then there are times I *love* technology :-)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Creating a contact as a copy of another contact
June 17, 2012, 07:01:16 am
Add this to .module file:

Code: [Select]
  function civiutils_include($filelist=null) {
    if (!module_exists('civicrm')) {
      return FALSE;
    }
    civicrm_initialize(TRUE);
    foreach($filelist as $file) {
      if (in_array($file,array('Config','DAO'))) {
        require_once "CRM/Core/$file.php";
      }
      else {
        require_once 'api/v2/' . $file . '.php';
      }
    }
    return true;
  }
}
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

davyivins

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 2
    • PURCO SA
  • CiviCRM version: 4.5
  • CMS version: Drupal 6.33
  • MySQL version: 5.5.34
  • PHP version: 5.4.33
Re: Creating a contact as a copy of another contact
June 17, 2012, 08:29:32 am
After removing the last } the module ran - but returns "DB Error: no such field".
 :-(
There are times I love technology...and then there are times I *love* technology :-)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Creating a contact as a copy of another contact
June 17, 2012, 08:41:59 am
There should be an error message with the offending SQL code.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Creating a contact as a copy of another contact

This forum was archived on 2017-11-26.