I have been trying to update the Team an Account is assigned to through the API but it doesn't seem to update. Has anyone tried to do this?
I have been trying to update the Team an Account is assigned to through the API but it doesn't seem to update. Has anyone tried to do this?
Hi Robert,
Are you trying to update team_id and team_set_id directly? or are you trying to update by using team_name?
Locally, I was able to use team_name to pass the list of teams i want:
PUT /Accounts/6cff862a-df96-11ed-843a-0242ac12000e
{ team_name: [ {id: "East", name: "East", name_2: "", primary: true, selected: false}, {id: "1", name: "Global", name_2: "", primary: false, selected: false}, {id: "West", name: "West"}, ] }
Hope this helps
I am using team_name object but I was only setting the id field with the actually team id from the database. My next question is should I be using the name field instead of the id field?
Just running through a test, it looks like you just need the ids in the payload:
[ {id: "East"}, {id: "1"}, {id: "West"}, ]
If this isn't working, you may have something updating team sets in SugarBPM, workflows, or logic hooks.
It's also worth noting that Sugar has a teams access check that will add the current users primary team if they no longer have access to the record when saving. Theres some additional information here on that scenario:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Configurator/Core_Settings/#disable_team_access_check
Just running through a test, it looks like you just need the ids in the payload:
[ {id: "East"}, {id: "1"}, {id: "West"}, ]
If this isn't working, you may have something updating team sets in SugarBPM, workflows, or logic hooks.
It's also worth noting that Sugar has a teams access check that will add the current users primary team if they no longer have access to the record when saving. Theres some additional information here on that scenario:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Configurator/Core_Settings/#disable_team_access_check
When you are using the id field are you sending the name of the Team in that field or the Sugar UUID?
I'm sending the id. I used the installer to create demo data and it creates teams with east and west as the ids.
Ok Thanks. I will have to dig deeper since the Team is not updating.
Can you share your API call and the payload?
Sorry it took me so long to respond. Anyway, I am using a custom endpoint but below is the code that actually does the work. I believe I am missing something. Yes a Teams update works when I use the standard Accounts API PUT. This custom endpoint was built to be able to just mass upload thousands of records at once and handle checking if the record exists and just updating with new or changed information.
private function _processEntry($module, $fieldsArray) { $Logger = Factory::getLogger('default'); if (array_key_exists('id', $fieldsArray)) { $sugarBean = BeanFactory::retrieveBean($module, $fieldsArray['id']); if (is_null($sugarBean)) { $Logger->debug('Record ' . $fieldsArray['id'] . ' does not exist'); $sugarBean = BeanFactory::newBean($module); /** * When creating a bean, you can specify a value in the id column as * long as that value is unique. During save, if the system finds an * id, it assumes it is an update. Setting new_with_id to true will * make sure the system performs an insert instead of an update. * * @var BOOL -- default false */ $sugarBean->new_with_id = true; }else{ $Logger->debug('Record ' . $fieldsArray['id'] . ' does exist'); } } else { $sugarBean = BeanFactory::newBean($module); } if (is_null($sugarBean)) { return null; } foreach ($fieldsArray as $field => $data) { $sugarBean->$field = $data; } $sugarBean->save(); return $sugarBean; }
For anyone interested, I have found the solution. See Manipulating Teams Programmatically - SugarCRM Support Site under the Replacing Teams. I had to also update my endpoint code to do this but here is what I got.
private function _processEntry($module, $fieldsArray) { $Logger = Factory::getLogger('default'); if (array_key_exists('id', $fieldsArray)) { $sugarBean = BeanFactory::retrieveBean($module, $fieldsArray['id']); if (is_null($sugarBean)) { $Logger->debug('Record ' . $fieldsArray['id'] . ' does not exist'); $sugarBean = BeanFactory::newBean($module); /** * When creating a bean, you can specify a value in the id column as * long as that value is unique. During save, if the system finds an * id, it assumes it is an update. Setting new_with_id to true will * make sure the system performs an insert instead of an update. * * @var BOOL -- default false */ $sugarBean->new_with_id = true; }else{ $Logger->debug('Record ' . $fieldsArray['id'] . ' does exist'); } } else { $sugarBean = BeanFactory::newBean($module); } if (is_null($sugarBean)) { return null; } foreach ($fieldsArray as $field => $data) { if (is_array($data)){ foreach ($data as $element => $value) { if (is_array($value)) { foreach ($value as $obj1 => $obj2) { $Logger->debug('Field: ' . $obj1 . ' Data: ' . $obj2); if ($field == 'team_name' && $obj1 == 'id') { $sugarBean->load_relationship('teams'); $sugarBean->team_id = $obj2; $sugarBean->teams->replace( array( $obj2 ) ); } } } else { if ($field == 'team_name' && $obj1 == 'id') { $sugarBean->load_relationship('teams'); $sugarBean->team_id = $obj2; $sugarBean->teams->replace( array( $obj2 ) ); } } } } else { $Logger->debug('Field: ' . $field . ' Data: ' . $data); $sugarBean->$field = $data; } } $sugarBean->save(); return $sugarBean; }