Issues with update() using app reference field
AnsweredOk so not sure the issue here but I can't find any answers in the API documentation and I'm getting desperate.
First I tried this (some things are hard coded for now just to make sure that there are no conflicts.:
try {
$new_student = $this->api->item->update(18087177,
array(
"students" => 19380159 //$student_id as an integer because this is an app ref field
)
);
** }
*catch (PodioError $e) {
* $error = "There was an error. The API responded with the error type '{$e->body['error']}' and the mesage '{$e->body['error_description']}'.";**
}
That did not work and it did not send me any error so I have no idea what the problem is, but then I tried this approach and got some result:
try {
$student_id = floatval($new_student['item_id']);
$new_student = $this->api->item->updateFieldValue(18087177,17703085,
array(
"values" => 19380159 //$student_ids
)
);
}
**catch (PodioError $e) {
*** $error = "There was an error. The API responded with the error type '{$e->body['error']}' and the mesage '{$e->body['error_description']}'.";*
}
This approach worked but it wiped all the app reference I already had loaded for the item, so then I figured I just need to send them all, but now I don't know how to do that. I tried sending as the following:
- "values" => 19380159,18088765 //$student_id
- "values" => array(19380159,18088765) //$student_id
Each of these result in an error message like the following:
"There was an error. The API responded with the error type 'invalid_value' and the message 'Invalid sub id u'0' (field: 17703085)'."
Ok so that about sums it up, now if I can just get some help, any help, I'm on a deadline that we passed on Monday so I really need this done and I'm on the home stretch. Thanks in advance.
-
I'll try that real quick too, I just got a result doing this:
$new_student = $this->api->item->updateFieldValue(18087177,17703085,
array(
19380159,
18088765
)
** );**My question though is since I need to put the new ID and the current IDs, is there an easy way to get the current IDs already attached to this item_id?
Thanks for the quick response as well I really appreciate it, trying to wrap this thing up tonight
-
I think I got it. I did this as a test and it seems to work so now I'm going to plug my variables back in and should be good to go :)
$test = $this->api->item->getFieldValue(18087177,DONOR_STUDENTS);
** $instance;**
** foreach($test as $i => $t){**
$instance[$i] = $t['value']['item_id'];
** }**
** try {**
$student_id = floatval($new_student['item_id']);
$new_student = $this->api->item->updateFieldValue(18087177,$student_id,$instance);
** }** -
Hey guys... related to Nick's question... I need to find a PHP code sample for how to create an item which has an app reference...
I am successfully creating my item which has fields "title" and "text" like this:
$fields = array(
array('external_id'=>'title', 'values'=>array('value'=>$this->title)),
array('external_id'=>'text', 'values'=>array('value'=>$this->template_content)),);
$template_item = $this->api->item->create($_SERVER['HELPDESK_TEMPLATES_APP_ID'] , array('fields' => $fields));
In this same app, if I have a field called "Release" and need to link this up to my "Releases" app item - assuming my Releases app item ID is stored in a variable called $ReleaseItemID, and and field ID of the Release variable is in var called $ReleaseFieldID... what is the syntax to link up the app reference?
Thanks for any help!
Patrick Steil -
All code untested because that's how I roll this morning. :)
With the new PHP client:
$field = new PodioAppItemField(array('field_id' => $ReleaseFieldID);
$field->set_value($releaseItemID);
$item = new PodioItem(array('app' => new PodioApp($app_id));
$item->fields = array($field);
$item->save();With the ancient PHP client you'll need to build your array or arrays yourself:
array('field_id' => $ReleaseFieldID, 'values' => array(array('value' => $ReleaseItemID));
// You may be able to get away with, but I'm unsure
array($ReleaseFieldID => $ReleaseItemID);
Please sign in to leave a comment.
Comments
6 comments