I am trying to autopopulate a relate field when creating an opportunity off of a contact. I have done extensive searching of these forums and the sugarcrm forums. I have found several ways of doing this but am stuck. I can get the contact name into my relate field, “contact_c” but every time I try to save the Opportunity, it gives and error - [color=#ff0000]No match for field: Contact[/color]
First, I created a view.edit.php at \custom\modules\Opportunities\views\view.edit.php and added the following into the display function.
I’ve also gone about it by creating a custom vardef - \custom\Extension\modules\Opportunities\Ext\Vardefs\vardef.ext.php
$dictionary[‘contacts’][‘fields’][‘contact_name’][‘populate_list’] = array(‘name’, ‘id’, ‘contact_name’);
$dictionary[‘opportunities’][‘fields’][‘contact_name’][‘field_list’] = array(‘contact_name’, ‘contact_id_c’, ‘contact_c’);
Finally, just for other testing purposes, I’ve put it right into opportunity.php using
$this->contact_c = $_REQUEST[‘contact_name’];
Any of these work for loading the contact name into my relate field. Clearly an event happens though upon putting focus onto that field and typing something because I can go into that field, delete the last letter on the name, put it back on, and the contact is found.
Thank you for the help. I tried the method described in the link by adding this function to Opportunity.php
function fill_in_additional_detail_fields() {
parent::fill_in_additional_detail_fields();
if ($_REQUEST['target_action']=="QuickCreate"){
//here we check if it is quick create
$contact_id = $_REQUEST['contact_id'];
if ($contact_id!=""){
//if we are here it means that we create a record from opportunity
$contact = new Contact();
$contact->retrieve($contact_id);
//you need to use inspect element in browser to find your names of account fields
$this->contact_c = $contact->contact_name;
$this->contact_id_c = $contact->contact_id;
}
}
}
That did not work. Upon clicking Create on the Opportunity, I get a blank area underneath the Opportunities title (see attached image). I tried doing an R&R but that hangs at Rebuilding relationships. Comment out the function I added and things return to normal.
New file create at custom/modules/opportunity/views/view.quickcreate.php
class OpportunityViewQuickcreate extends ViewQuickcreate
function preDisplay(){
parent::preDisplay();
if (isset($_REQUEST[‘parent_id’]) && $_REQUEST[‘parent_id’] != ‘’ && isset($_REQUEST[‘parent_type’]) && $_REQUEST[‘parent_type’] == ‘Contacts’){
$cont = new Contact();
$cont->retrieve($_REQUEST[‘parent_id’]);
//say the fields are company_id and company_name in Companies
//and company_id_c and company_name_c in Contracts
//assuming company is a relate field you’ll need to map both
$_REQUEST[‘contact_id_c’] = $cont->contact_id;
$_REQUEST[‘contact_c’] = $cont->contact_name;
}
}
}
Here is the first bit of code I tried. This prevented anything from happening.
function fill_in_additional_detail_fields() {
parent::fill_in_additional_detail_fields();
if (@$_REQUEST['target_action']=="QuickCreate"){
//here we check if it is quick create
$cont_id = @$_REQUEST['contact_id'];
if ($contact_id!=""){
//if we are here it means that we create a record from opportunity
$cont= new Opportunity();
$cont->retrieve($cont_id);
//you need to use inspect element in browser to find your names of account fields
$this->contact_c = $cont->contact_name;
$this->contact_id_c = $cont->contact_id;
}
}
}
Here is the code for the view.quickcreate.php file that I also tried. This did nothing.
class OpportunityViewQuickcreate extends ViewQuickcreate
function preDisplay(){
parent::preDisplay();
echo "view.quickcreate.php";
if (isset($_REQUEST['parent_id']) && $_REQUEST['parent_id'] != '' && isset($_REQUEST['parent_type']) && $_REQUEST['parent_type'] == 'Contacts'){
$cont = new Contact();
$cont->retrieve($_REQUEST['parent_id']);
//say the fields are company_id and company_name in Companies
//and company_id_c and company_name_c in Contracts
//assuming company is a relate field you'll need to map both
$_REQUEST['contact_id_c'] = $cont->contact_id;
$_REQUEST['contact_c'] = $cont->contact_name;
}
}
}
Hi beasly,
I am facing exactly the same problem as you did.
In the quotes module I have a few custom fields that are getting populated from the other modules.
For example I have a “relate” field for accounts that I want to get pre populated.
When I’m creating the quotes from opportunity module, I wrote some custom code to get the account relate field pre-populated
but upon saving, it says no match found and exactly like you did, I tried to edit the content and then it was able to find it.
I went through the code that you’ve posted, But I couldn’t understand it.
Can I shoot my questions?
It appears that the preDisplay function is skipped for Quickcreate form from subpanels, but cant find a reason why. See my post on the Sugarcrm forum also: https://community.sugarcrm.com/message/80247
Found a way round it, skip using the preDisplay function, and just put the “pre fill field” code in the display function instead, but before calling parent::display()
Still doesnt make sense why preDisplay is not firing for subpanel forms.
Hi
are you still looking for the same?, then I would like to share my knowledge as per your question I understand that you are trying to create a custom field contact module in the opportunity module, Right?