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?
hey @Urvi Iāve got a couple of questionsā¦ does this still work (7.13)? Also, Iām unclear about the file path. In my case I want to populate some fields in the Tasks subpanel of the Quotes module. Do I need to put this inā¦/AOS_Quotes/ā¦ or ā¦/Tasks/ā¦ ?
What Iām trying to do is populate the account name in the Task subpanel of the Quotes module. So when I create a task from the quote, the Quote relationship is already populated by default. I just want to be able to populate the account thatās related to the quote. Its stored in the quote as billing_account