/**
  * This function handles turning the API's version of a teamset into what we actually store
  * @param SugarBean $bean - the bean performing the save
  * @param array $params - an array of paramester relevant to the save, which will be an array passed up to the API
  * @param string $fieldName - The name of the field to save (the vardef name, not the form element name)
  * @param array $properties - Any properties for this field
  */
 public function apiSave(SugarBean $bean, array $params, $fieldName, $properties)
 {
     // Find the primary team id, or the first one, if nothing is set to primary
     $teamList = $params[$fieldName];
     $ret = $this->fixupTeamList($teamList);
     $teamIds = $ret['teamIds'];
     $primaryTeamId = $ret['primaryTeamId'];
     if (count($teamIds) == 0) {
         // There are no teams being set, set the defaults and move on
         $bean->setDefaultTeam();
         return;
     }
     if (empty($primaryTeamId)) {
         // They didn't specify a primary team, so I'm just going to set it to the first one
         $primaryTeamId = $teamIds[0];
     }
     $bean->team_id = $primaryTeamId;
     if ($bean->load_relationship('teams')) {
         $bean->teams->replace($teamIds, array(), false);
     }
 }