How to set multiple team when create new record via logic hook

Hi,

I try to create case record and put multiple teams, one is primary team(fetch from parent) another is team id 

but it doesn't work.

$c = BeanFactory::newBean('Cases');
$c->name = 'Test';
$c->status = 'New';
$c->assigned_user_id = 'xxxxxxxx-bbbb-cccc-yyyy-eeeeeeeeeeee';
$c->team_id = array(
     array(id => $bean->team_id, primary => true),
     array(id => 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee')
);
$c->account_id = $bean->id;
$c->priority = 'P1';
$c->save();

  

It not set primary team after created a record but all team have been added.

How do I fix my code?

Please help 

Sugar 7.7.1.0

Thanks,

Autchara

Parents Reply Children
  • Yes, thank you I have solution from this article. 

    $c = BeanFactory::newBean('Cases');
    $c->name = 'Test';
    $c->status = 'New';
    $c->assigned_user_id = 'xxxxxxxx-bbbb-cccc-yyyy-eeeeeeeeeeee';  
    if($c->load_relationship('teams')){
          $c->team_id = $primary_team_id;
          $c->teams->replace(array(
              $primary_team_id,
              $another_team_id
            )
          );
    }
    $c->account_id = $bean->id;
    $c->priority = 'P1';
    $c->save();