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) »
  • creating a Line Item using API throwing error
Pages: [1]

Author Topic: creating a Line Item using API throwing error  (Read 930 times)

developer

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 4.2+
  • CMS version: drupal 7.x/6.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
creating a Line Item using API throwing error
May 23, 2013, 03:53:20 am
Hi Experts,

Im trying to use API and Entity Line Item to create a line item record.. but its throwing the following error
 [nativecode=1062 ** Duplicate entry 'civicrm_contribution-1-1-1' for key 'UI_line_item_value']' (length=385)
  'trace' => string '#0 [internal function]: CRM_Core_Error::exceptionHandler(Object(DB_Error))

Im getting the same error when i tried manually using Sql statement as well

my sql query is : INSERT INTO civicrm_line_item (entity_table , entity_id , price_field_id , label , qty , unit_price , line_total , participant_count , price_field_value_id , financial_type_id , deductible_amount ) VALUES ('civicrm_contribution' ,  1 ,  1 , 'Edoka' ,  1 ,  444 ,  444 ,  1 ,  1 ,  1 ,  0 )


Can anyone pls help me to solve this..

Many Thanks in advance!!
« Last Edit: May 23, 2013, 04:16:12 am by developer! »

developer

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 4.2+
  • CMS version: drupal 7.x/6.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: creating a Line Item using API throwing error
May 23, 2013, 06:34:27 am
Thanks for your time reading this guys..

I could be able to see there is a MUL key on four fields in civicrm_line_item table.
which together forming a key.
im now trying to get rid of this..


mysql documentation:
A UNIQUE index may display as MUL if several columns form a composite UNIQUE index; although the combination of the columns is unique, each column can still hold multiple occurrences of a given value.

--Cheers

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: creating a Line Item using API throwing error
May 28, 2013, 09:33:58 pm
Using "show create table civicrm_line_item", I can see that UNIQUE index you mention:

Code: [Select]
  UNIQUE KEY `UI_line_item_value` (`entity_table`,`entity_id`,`price_field_value_id`,`price_field_id`),

This seems to be saying that given a particular record (e.g. given entity_table="civicrm_participant" and entity_id=5), each price field value can only be used once. This seems like a sensible restriction based on how "price sets" work.

(Aside: There is probably some difference between Civi's "PriceSets/LineItems" model and the mental model of a paper-based "Order/LineItem" form. In some "Order/LineItem" models, you could create two separate line-items to purchase two copies of the same product. In Civi's model, I don't think that would happen -- if multiple copies of an item can be purchased, then you would design price-fields specifically to allow that.)

I guess the next questions -- Why is it trying to create a new price-field-value when one already exists? If you want to update an existing item, most APIs will accept the existing item's "id". (Warning: I haven't used the particular APIs that you're using, so I don't know for sure.)

developer

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 4.2+
  • CMS version: drupal 7.x/6.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: creating a Line Item using API throwing error
May 29, 2013, 01:50:29 am
Thanks for your reply totten. I have creatd a priceset and price field. and using this price_field_id to create a line item with other user supplied values..

Its working fine now..


Thanks alot :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • creating a Line Item using API throwing error

This forum was archived on 2017-11-26.