Sugar 7.5 Case's team re-assignment : how do i change team in related email and note ?

Hello there !

It's me again, with a quite strange and mind breaker problem.

What I would like Sugar to do :

I have set the Inbound Emails to generate Cases from a lot of email groups. Generally, theses cases are split between 2 Teams assignment (let's say Team A and Team B)

But, sometimes, the original email has been sent by mistake to the wrong Checkbox, and the user has to re-assign the Case to the other team. So Case01 is assigned from Team A to Team B.

The normal behavior should have been the following : The attached email (the original one) and all the attachments should be re-assigned to team B when a Case is re-assigned from Team A to Team B.

The problem :

Sugar did not developp any of these and the support told me it would be an idea. (see Case #250492 on support portal, if you can)

What i tried :

1) Setting a workflow

Firstly, I tried to set a Workflow. This workflow is launched whenever an existing record is saved. When Team(ID) is modified, the actions are : Updating a field in related module Email : Set Team(ID) to "Current Team of the triggered record".

This totally fails.

2) Writing a after_save Logic hook :

I've tried to create an after_save logic hook under Cases module where i test the $bean->fetched_row['team_id'] to say if it has changed or not. If yes, i would like to take every email related and modify their team assignment. And i would like to get every attachment related to every email and changed their tema assignment too.

I wanted to test the $bean->fetched_row['team_id'], but it seems that first, my code traces into sugarcrm.log does not work, but plus : the tema_id does not change !!! Or i'm calling the bad $bean->fetched_row ?

Please help me. Here is my code :

in custom/Extension/modules/Cases/Ext/LogicHooks/logichooks.php

In custom/modules/Cases/reassignmentRelated.php

fatal('Cases team reassignment: id team  before = '.$bean->fetched_row['team_id'].' AND team assignment now = '.$bean->team_id);                $bean->field_text_c = $bean->fetched_row['team_id']." TEST apres ".$bean->team_id;             }         }     } ?>

Please help me, i'm sure i am wrong someway with the $bean->fetched_row... or maybe you could help me with the workflow ?

Thanks a lot !

  • Okay,

    I have something kind of working.I wrote the following class and function which are called in an after_save logic hook, on Cases module :

    load_relationship('emails');             $emails = $bean->emails->getBeans();             if(!empty($emails)){                 foreach($emails as $email)                 {                     $email_team = $email->team_id;                     //Test if Case and email are assigned to the same primary team                     if($email_team != $bean->team_id){                         $email->load_relationship('teams');                         $email->team_id = $bean->team_id;                         $email->teams->replace(                             array(                                 $bean->team_id,                             )                         );                         $email->load_relationship('notes');                         $notes = $email->notes->getBeans();                         if(!empty($notes)){                             foreach($notes as $note)                             {                                 $note_team = $note->team_id;                                 if($note_team != $bean->team_id)                                 {                                     $note->load_relationships('teams');                                     $note->team_id = $bean->team_id;                                     $note->teams->replace(                                         array(                                             $bean->team_id,                                         )                                     );                                     $note->save();                                 }                             }                         }                         $email->save();                     }                 }             }         }     } ?>

    So, the assignation works pretty well.

    But I have a problem :

    WHen user import1 (which is a standard user) from Team Contrat re-assign the case 192 to user import2  in Team Sinistre, I have an error message popping. See the attachment :

    Demandes » SugarCRM - Mozilla Firefox.jpg

    In english, it says something like "Error. An error occurred while connecting to the server".

    For me, because re-assignment is badly managed by Sugar, it is considered as an error...

    So, the user does not see what if the changes really occured, and could be tempted to try and modify other informations., I would like the reassignment to lead to the Cases list view with a popup saying "Record well reassigned !"

    So, how could I manage that ?

    DO you have any idea ?

  • Okay, i'll open a new thread for my logical/redirection error problem.

    So for the moment this is solved, see previous message.