AnsweredAssumed Answered

Problem filling fields with parent data on creating a new "item"

Question asked by Davide Davide on Apr 17, 2014
Latest reply on Apr 17, 2014 by Davide Davide
Hi,
I want as the title says I want to fill fields with data taken from parent.
In my case, the parent is Cases and the child is Tasks (activities), in the Case I've added 3 contacts and in Tasks I've added 2 contacts (1 was already there) and I want to fill the 3 Task's contacts with the 3 Case's contacts.
I tried through both custom controller.php and view.edit.php and both worked when I modify an existing Task, but not when I'm creating a new Task.
Here is the code in controller.php:
  1.     function action_editview() {
  2.         $this->view = 'edit';
  3.         $GLOBALS ['view'] = $this->view;
  4.        
  5.         $tipo_parente = '';
  6.         $id_parente = '';
  7.        
  8.         if($this->record==null || $this->record==''){
  9.             $tipo_parente = $this->return_module;
  10.             $id_parente = $this->return_id;
  11.         } else {
  12.             $tipo_parente = $this->bean->parent_type;
  13.             $id_parente = $this->bean->parent_id;
  14.         }
  15.        
  16.        
  17.         if ($tipo_parente == "Cases" && ($this->bean->contact_id == null || $this->bean->contact_id == '' || $this->bean->contact_id_c == null || $this->bean->contact_id_c == '' || $this->bean->contact_id1_c == null || $this->bean->contact_id1_c == '')) {
  18.             $case = new aCase();
  19.             $case->retrieve($id_parente);
  20.             $contatto = new Contact();
  21.             $contatto1 = new Contact();
  22.             $contatto2 = new Contact();
  23.             $contatto->retrieve($case->contact_id_c);
  24.             $contatto1->retrieve($case->contact_id1_c);
  25.             $contatto2->retrieve($case->contact_id2_c);
  26.            
  27.             if ($this->bean->contact_id == null || $this->bean->contact_id == '') {
  28.                 $this->bean->contact_id = $case->contact_id_c;
  29.                 $this->bean->contact_name = $contatto->salutation . " " . $contatto->first_name. " " . $contatto->last_name;
  30.             }
  31.             if ($this->bean->contact_id_c == null || $this->bean->contact_id_c == '') {
  32.                 $this->bean->contact_id_c = $case->contact_id1_c;
  33.                 $this->bean->contatto_aggiuntivo_1_c = $contatto1->salutation . " " . $contatto1->first_name. " " . $contatto1->last_name;
  34.             }
  35.             if ($this->bean->contact_id1_c == null || $this->bean->contact_id1_c == '') {
  36.                 $this->bean->contact_id1_c = $case->contact_id2_c;
  37.                 $this->bean->contatto_aggiuntivo_2_c = $contatto2->salutation . " " . $contatto2->first_name. " " . $contatto2->last_name;
  38.             }
  39.         }
  40.     }
In the view.edit.php I'd put the same code except the beginning of the function:
  1.  public function preDisplay() {
  2.         parent::preDisplay ();
  3.         if (isset ( $_REQUEST ['parent_id'] ) && $_REQUEST ['parent_id'] != '' && isset ( $_REQUEST ['parent_type'] ) && $_REQUEST ['parent_type'] == 'Cases') {
  4.             $case = new aCase ();
  5.             $case->retrieve ( $_REQUEST ['parent_id'] );
  6. ...

Outcomes