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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Chaining event get to loc block get for events without a loc block
Pages: [1]

Author Topic: Chaining event get to loc block get for events without a loc block  (Read 477 times)

johanv

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 5
  • #chiro #geek #linux #beer
    • my homepage
  • CiviCRM version: 4.7.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.x
Chaining event get to loc block get for events without a loc block
March 21, 2015, 02:30:21 pm
Hi all,

If I want to retrieve an event and its loc block, I can do this like this:

Code: [Select]
    $result = civicrm_api3('Event', 'getsingle', array(
    'sequential' => 1,
    'return' => "title,loc_block_id",
    'id' => 1500,
    'api.LocBlock.get' => array('id' => "\$value.loc_block_id"),
    ));

If the event has a loc block, this works:
Code: [Select]
    {
    "id":"1500",
    "title":"Startdag regio Oost-Vlaanderen 2007",
    "event_title":"Startdag regio Oost-Vlaanderen 2007",
    "loc_block_id":"169",
    // I omitted a lot of custom field results I didn't request.
    "price_set_id":"69",
    "api.LocBlock.get":{
    "is_error":0,
    "version":3,
    "count":1,
    "id":169,
    "values":[{
    "id":"169",
    "address_id":"11018"
    }]
    }
    }

But if I do the same for an event that doesn't have a loc block:

Code: [Select]
    $result = civicrm_api3('Event', 'getsingle', array(
    'sequential' => 1,
    'return' => "title,loc_block_id",
    'id' => 1000,
    'api.LocBlock.get' => array('id' => "\$value.loc_block_id"),
    ));

The API returns an error:

Code: [Select]
    {
    "error_field":"id",
    "type":"integer",
    "error_code":2001,
    "entity":"Event",
    "action":"get",
    "is_error":1,
    "error_message":"Error in call to LocBlock_get : id is not a valid integer"
    }

I guess the fact that this event has no loc block id causes the chaining to fail. But is this error message expected? Or is this a bug, and should the API return
Code: [Select]
    {
    "id":"1000",
    "title":"IK ZENNEVALLEI 2011",
    "event_title":"IK ZENNEVALLEI 2011",
    "is_error":0,
    "api.LocBlock.get":{
    "is_error":0,
    "version":3,
    "count":0,
    "values":[]
    }
    }

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Chaining event get to loc block get for events without a loc block
March 21, 2015, 02:40:21 pm
Weeell... I can see why that happens. Loc block id is not a valid integer, but at minimum it seems like the outer call should still succeed even if the inner one fails.
Try asking your question on the new CiviCRM help site.

johanv

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 5
  • #chiro #geek #linux #beer
    • my homepage
  • CiviCRM version: 4.7.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.x
Re: Chaining event get to loc block get for events without a loc block
March 24, 2015, 02:33:16 am
I created an issue: https://issues.civicrm.org/jira/browse/CRM-16168

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Chaining event get to loc block get for events without a loc block

This forum was archived on 2017-11-26.