2

I have an item with a referenced field to another app. A call has an assigned client.

I use this library: http://podio.github.io/podio-php/

I followed this article: http://podio.github.io/podio-php/fields/

I want to update an existing item by changing the item_id of its field that's referencing another app. The item_id already exists in the other app.

Here's what I tried (this happens when a Webhook is triggered):

$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array(
    array('item_id' => $id_client)
);
$item->save(array(
    'hook'      => false,
    'silent'    => true
));

AND

$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array('item_id' => $id_client);
$item->save(array(
    'hook'      => false,
    'silent'    => true
));

Where 'client' is the external id of the field and $id_client is an integer number. Here's the error I get:

[18-Aug-2014 17:33:30 UTC] PHP Notice:  Indirect modification of overloaded property PodioItem::$field has no effect in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66
[18-Aug-2014 17:33:30 UTC] PHP Warning:  Creating default object from empty value in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66

If anyone could explain to me why this isn't working I'd be really grateful. The provided documentation is not clear on that subject.

Thank you!

SOLUTION

I got it to work this way, credits to Andreas:

if(!isset($item->fields['client']->values[0]->item_id)){
    $item->fields['client'] = new PodioAppItemField();
    $item->fields['client']->values = array(
        array('item_id' => $id_client)
    );
    $item->save(array(
        'hook'      => false,
        'silent'    => true
    ));
}
Vincent Poirier
  • 4,298
  • 5
  • 21
  • 25

1 Answers1

3

You're getting this error because the client field doesn't exist on your item yet. So you're trying to set values for something that doesn't exist.

You need to do something like (untested, but should work):

$item = PodioItem::get($_POST['item_id']);

if (!isset($item->fields['client'])) {
    $item->fields['client'] = new PodioAppItemField();
}

$item->fields['client']->values = array(
    array('item_id' => $id_client)
);
$item->save(array(
    'hook'      => false,
    'silent'    => true
));

When you get an item from Podio you won't get all fields in the app, only that ones that have values for that particular item. So you have to check if your particular field is present before trying to set values on it.

  • It worked! The only difference is that I used `$item->fields['client']` instead of `$item['client']` and I used `isset()` to make sure there's no value. Does the associative array really work for the item values? I checked the green mark, is that all I have to do to give you credits? – Vincent Poirier Aug 21 '14 at 00:01
  • Ah, those were brainfarts on my end. I've updated the code above appropriately for the next person who stumbles past this – Andreas Haugstrup Pedersen Aug 21 '14 at 05:53