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 (Moderator: Donald Lobo) »
  • Custom Fields in Custom Groups - "Already Exists" error
Pages: [1]

Author Topic: Custom Fields in Custom Groups - "Already Exists" error  (Read 1219 times)

Tom-Tigerfish

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
  • CiviCRM version: 3.4.1
  • CMS version: Drupal 6
  • MySQL version: 5.1.36
  • PHP version: 5.2.11
Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 03:45:11 am
Hi Guys

I have recently upgraded to CiviCRM 3.4.1

I am trying to add a new custom group following the exact same method as I did in older version but I am not able to create the custom field with the same name as before.

When trying to create the custom field with the required name I get the following error message

Please correct the following errors in the form fields below:
    * Custom field 'Ticket type' already exists in Database.

If anyone can shed any light on this or point me in the direction of a fix that would be most appreciated

Thank You

Tom

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 03:48:30 am
Can you use a different name to create the field and then go back and edit the label afterward to be what you want?
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.

Tom-Tigerfish

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
  • CiviCRM version: 3.4.1
  • CMS version: Drupal 6
  • MySQL version: 5.1.36
  • PHP version: 5.2.11
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 03:51:24 am
No,

Good idea but it didn't work,

I got the same error message when trying to save the field with the correct name after creating it with a dummy name ???

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 03:54:56 am
More explanations:

The label is used to generate a name for the custom field when you create it.

If you change the label after, it won't/shouldn't change the name.

Can you investigate what's happening in the code when you save it? it's in CRM/Custom/Form/Field.php

We probably need to expose the name on the web interface, and let the user choose it too (ala drupal), as it will soon be more exposed (eg in the API).

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Tom-Tigerfish

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
  • CiviCRM version: 3.4.1
  • CMS version: Drupal 6
  • MySQL version: 5.1.36
  • PHP version: 5.2.11
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 04:04:20 am
I will have a look in to this more closely after lunch

The main issue this is causing if I cant sort it out is that the Drupal site also has Ubercart and in this case a custom module that sells event tickets,

When a user buys a ticket(s) the module posts some data to Civi so this is why the filed names need to be the same otherwise we are looking at having to rewrite a couple of different ubercart modules

Tom-Tigerfish

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
  • CiviCRM version: 3.4.1
  • CMS version: Drupal 6
  • MySQL version: 5.1.36
  • PHP version: 5.2.11
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 05:45:18 am
Hi Xavier,

Any idea why the formRule function is setting an error for a field name that already exists ???

I am about to try (locally) just commenting out the line that is setting this error to test the consequences


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 08:02:28 am

I think the only rule should be:

Two fields in the same group should not have the same label and same name. If we automatically figure the name, we should add a random number at the end to distinguish labels

Someone might have a use case where they want two fields in the same group to have the same label, in which case we might want to consider that rule also

Code patches AND unit tests to do the above would be great. We should handle custom fields and profile fields in the same manner.

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Tom-Tigerfish

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
  • CiviCRM version: 3.4.1
  • CMS version: Drupal 6
  • MySQL version: 5.1.36
  • PHP version: 5.2.11
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 08:13:18 am
Hi Lobo

Thanks for the reply

I have tested a fudge fix and although it works for now I have disabled the test for fields of the same name

in CRM/Custom/Form/Field.php

Line 486 looks like it is causing the problem but i have decided to kill the whole test as I know we wont be breaking the rules as they were.

select count(*) from civicrm_custom_field where ( name like %1 OR label like %2 ) and id != %3'

I think like you say that the custom fields are not being associated with the group they are being created for.

I have changed line 490 from:

if ( $fldCnt) {

to:

if ( $fldCnt == 'Fudge' ) {

A patch would be very much appreciated

Thanks

Tom

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom Fields in Custom Groups - "Already Exists" error
June 03, 2011, 08:28:24 am
Quote from: Donald Lobo on June 03, 2011, 08:02:28 am
Two fields in the same group should not have the same label and same name. If we automatically figure the name, we should add a random number at the end to distinguish labels

For the api (cf. discussion with colemans), it would be super useful to keep the rule

Quote
Each field has a unique name, no matter the group.

I'm not sure how someone could distinguish between two fields that have the same label in the same group, but for the api, doesn't matter.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom Fields in Custom Groups - "Already Exists" error

This forum was archived on 2017-11-26.