AnsweredAssumed Answered

[SOLVED]Creating contact through popup search : getting related account info to fill contact fields

Question asked by Gaelle Fernandez on Mar 20, 2014
Hello everybody!

I have a problem extremly long to explain :

What i have :
On sugar enterprise 6.5.15,

When creating a case, i have the field "Contact", which is a relationship field (NOT a related). When clicking the little arrow, it opens a popup containing my contacts and the search.

Okay, now let's go deeper :

When this popup is opened, i have the possibility of creating a Contact, by clicking "Create". It opens the form to fill. That works well.

Let's go even more deeper :

In this create form, i have a field, a relationship one, called "account_name", which opens a new popup with the search's field and all my accounts. When i click on one of them, it fills my contact "account_name" field.

Now, what i want to do :
When i fill the account_name field on contact form, i want to retrieve  "address" and "phone" information from account, and fill "address" and "phone" fields of contact.

I've made it for editview and it works, and it works in Contact's subpanel too.

What is my issue :
I have the little sugar Alert popup saying "Hey be careful, you will replace address information by new one" and it gives me the informations from account.
But no field is filled (nor account_name nor phone nor address).

I think maybe because we opened a popup in a popup, sugar is lost and does not know which field to fill..

My code :

I've changed account_name definition in custom/module/Contacts/metadata/editviewdefs.php and in custom/module/Contacts/metadata/quickcreatedefs.php and added the code below :
'displayParams' =>             array (
 'field_to_name_array' => 
   array (
      'name' => 'account_name',
      'id' => 'account_id',
      'billing_address_street' => 'primary_address_street',
      'billing_address_city' => 'primary_address_city',
     'billing_address_postalcode' => 'primary_address_postalcode',
     'billing_address_state' => 'primary_address_state',
      'billing_address_country' => 'primary_address_country',
      'phone_office' => 'phone_work',
   'call_back_function' => 'set_return_FieldsFromAccount',

And then, in custom/modules/Contacts/views/view.edit.php and in custom/modules/Contacts/views/view.quickcreate.php, i added this javascript function :
$jsscript = <<<EOQ                   <script>
set_return_FieldsFromAccount(popup_reply_data) //OKE 2014/03/17 FE03 Mantis 22741     {
   var name_to_value_array = popup_reply_data.name_to_value_array;
So, as I said, this works for editView. but not for quickcreate on that special popup.

Here is the image of the result i have.


Thanks by advance for your time!

EDIT 25/03/2014 : Problem Solved!
 Well, I've solved the problem, but i don't really know how.. i've added the set_return_FieldsFromAccount function to custom/modules/Contacts/contact.js, and included this one into the custom/modules/metadata/quickcreateviewdefs.php . My field is still calling the function. It didn't work for a while, but now it does, even if i don't know why it didn't want to work.
So now it does. Hope this will help anyone who encounter the same issue!