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) »
  • Update custom field in Activities, using SQL?
Pages: [1]

Author Topic: Update custom field in Activities, using SQL?  (Read 701 times)

coopersquare

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
    • Cooper Square Committee
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress 3.8
  • MySQL version: 5.1
  • PHP version: 5.3.3
Update custom field in Activities, using SQL?
January 23, 2014, 08:44:40 am
I greatly appreciate others' input on how I could DELETE activities using their IDs in one command in the SQL command line of my database.  Now, I want to UPDATE activities.  Many activities have in their Subject Line, a code for topic. I created a Custom Multiple Choice field whose values match those codes.  So it could be a simple Batch Update, of making all Activities where Subject = "CN", now have a "CN" in that Custom field.

Only problem is, there are about 2500 Activities, and one can only Batch Update 100 activities at a time on the front-end.  Is there a way to do this in SQL that would save time?

(If Search Builder would allow me to get a list of Activities where the Custom field is Empty, that would help, but Search Builder can only return results as Contacts, not Activities (or any other record type), which is annoying.)

Thanks!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Update custom field in Activities, using SQL?
January 23, 2014, 10:58:11 am
Assuming you have some mySQL experience - you can get started by identifying the custom data set table where this custom field is stored. Table naming for custom data storage is 'civicrm_value_<your_custom_data_set_name>_<ID> . Once u find the table it should be easy to identify the column by field name.
Protect your investment in CiviCRM by  becoming a Member!

coopersquare

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
    • Cooper Square Committee
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress 3.8
  • MySQL version: 5.1
  • PHP version: 5.3.3
Re: Update custom field in Activities, using SQL?
January 24, 2014, 10:58:26 am
Thanks a bunch! Yeah with some Googling I was able to piece together the syntax, and successfully ran this command!:
below I call it customtable.field for clarity.

Code: [Select]
UPDATE customtable
INNER JOIN civicrm_activity ON (customtable.entity_id = civicrm_activity.id)
SET customtable.field = civicrm_activity.subject
WHERE customtable.entity_id IN ( a bunch of Activity IDs here to update )

I had to put in a WHERE statement, since the field is multiple choice, and while Subject lines have them separated by comma, space (e.g. "TA, HS"), customtable.field encodes a similar selection as  "TAHS".  So I was only able to update the 75% of Activities where only one Issue Area was selected. Is there any good way for the other Activities, to have the SQL database take the value in table 1, drop ", " and put it into table 2?  (it sees .subject = "TA, HS", and sets .field = "TAHS")

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Update custom field in Activities, using SQL?
January 24, 2014, 01:50:21 pm
Hmm - if the custom field is checkbox / multiple select - the values are delimited in the DB column with an 'invisible' Ctrl+A character. You'll need to do some more googling and figure out mysql syntax for that type of substitution.
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Update custom field in Activities, using SQL?

This forum was archived on 2017-11-26.