How do I Auto Populate a Custom Relate Field when Creating a Record from a Subpanel?

Hi all,

I'm attempting to populate a custom relate field (primary_contact_c) when creating an opportunity from a contact using the subpanel; the relate field in the opportunity should be populated with the contact that it is being created from.

I've found a few articles on here and on other sites which ask similar things but I've not made much progress with this.

Any help would be very much appreciated.

Many thanks in advance.

Parents
  • Thanks, Andre and Maryam for your responses.

    I'm not sure if this is considered to be basic stuff but I was eventually able to work this out by adding the below code to the vardef found at custom\extension\modules\Opportunities\Ext\Vardefs\sugarfield_primary_contact_c.php

    $dictionary['Opportunity']['fields']['primary_contact_c']['name']='primary_contact_c';

    $dictionary['Opportunity']['fields']['primary_contact_c']['rname']='name';

    $dictionary['Opportunity']['fields']['primary_contact_c']['id_name']='contact_id_c';

    $dictionary['Opportunity']['fields']['primary_contact_c']['vname']='LBL_PRIMARY_CONTACT';

    $dictionary['Opportunity']['fields']['primary_contact_c']['type']='relate';

    $dictionary['Opportunity']['fields']['primary_contact_c']['table']='contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['join_name']='contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['isnull']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['module']='Contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['dbType']='varchar';

    $dictionary['Opportunity']['fields']['primary_contact_c']['link']='contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['len']='255';

    $dictionary['Opportunity']['fields']['primary_contact_c']['source']='non-db';

    $dictionary['Opportunity']['fields']['primary_contact_c']['unified_search']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['required']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['importable']='required';

    $dictionary['Opportunity']['fields']['primary_contact_c']['required']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['related_field']= array('contact_id_c');

    $dictionary['Opportunity']['fields']['primary_contact_c']['exportable']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['export_link_type']='one';

    This pre-populates the relate field in opportunities with the contact name when creating an opportunity from that contact but the link tries to take you to the the opportunity rather than the contact.

    With that in mind I also tried to amend an existing vardef in the same folder which was sugarfield_contact_id_c and added in the below code:

    $dictionary['Opportunity']['fields']['contact_id_c']['name']='contact_id_c';
    $dictionary['Opportunity']['fields']['contact_id_c']['vname']='LBL_CONTACT_ID';
    $dictionary['Opportunity']['fields']['contact_id_c']['id_name']='contact_id';
    $dictionary['Opportunity']['fields']['contact_id_c']['type']='relate';
    $dictionary['Opportunity']['fields']['contact_id_c']['link']='contacts';
    $dictionary['Opportunity']['fields']['contact_id_c']['rname']='id';
    $dictionary['Opportunity']['fields']['contact_id_c']['source']='non-db';
    $dictionary['Opportunity']['fields']['contact_id_c']['audited']=true;
    $dictionary['Opportunity']['fields']['contact_id_c']['dbType']='id';
    $dictionary['Opportunity']['fields']['contact_id_c']['module']='Contacts';
    $dictionary['Opportunity']['fields']['contact_id_c']['massupdate']=false;

    I'm sure there are improvements that can be made on all of the above but this seems to work and I hope it helps anyone who has the same issues.

Reply
  • Thanks, Andre and Maryam for your responses.

    I'm not sure if this is considered to be basic stuff but I was eventually able to work this out by adding the below code to the vardef found at custom\extension\modules\Opportunities\Ext\Vardefs\sugarfield_primary_contact_c.php

    $dictionary['Opportunity']['fields']['primary_contact_c']['name']='primary_contact_c';

    $dictionary['Opportunity']['fields']['primary_contact_c']['rname']='name';

    $dictionary['Opportunity']['fields']['primary_contact_c']['id_name']='contact_id_c';

    $dictionary['Opportunity']['fields']['primary_contact_c']['vname']='LBL_PRIMARY_CONTACT';

    $dictionary['Opportunity']['fields']['primary_contact_c']['type']='relate';

    $dictionary['Opportunity']['fields']['primary_contact_c']['table']='contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['join_name']='contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['isnull']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['module']='Contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['dbType']='varchar';

    $dictionary['Opportunity']['fields']['primary_contact_c']['link']='contacts';

    $dictionary['Opportunity']['fields']['primary_contact_c']['len']='255';

    $dictionary['Opportunity']['fields']['primary_contact_c']['source']='non-db';

    $dictionary['Opportunity']['fields']['primary_contact_c']['unified_search']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['required']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['importable']='required';

    $dictionary['Opportunity']['fields']['primary_contact_c']['required']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['related_field']= array('contact_id_c');

    $dictionary['Opportunity']['fields']['primary_contact_c']['exportable']=true;

    $dictionary['Opportunity']['fields']['primary_contact_c']['export_link_type']='one';

    This pre-populates the relate field in opportunities with the contact name when creating an opportunity from that contact but the link tries to take you to the the opportunity rather than the contact.

    With that in mind I also tried to amend an existing vardef in the same folder which was sugarfield_contact_id_c and added in the below code:

    $dictionary['Opportunity']['fields']['contact_id_c']['name']='contact_id_c';
    $dictionary['Opportunity']['fields']['contact_id_c']['vname']='LBL_CONTACT_ID';
    $dictionary['Opportunity']['fields']['contact_id_c']['id_name']='contact_id';
    $dictionary['Opportunity']['fields']['contact_id_c']['type']='relate';
    $dictionary['Opportunity']['fields']['contact_id_c']['link']='contacts';
    $dictionary['Opportunity']['fields']['contact_id_c']['rname']='id';
    $dictionary['Opportunity']['fields']['contact_id_c']['source']='non-db';
    $dictionary['Opportunity']['fields']['contact_id_c']['audited']=true;
    $dictionary['Opportunity']['fields']['contact_id_c']['dbType']='id';
    $dictionary['Opportunity']['fields']['contact_id_c']['module']='Contacts';
    $dictionary['Opportunity']['fields']['contact_id_c']['massupdate']=false;

    I'm sure there are improvements that can be made on all of the above but this seems to work and I hope it helps anyone who has the same issues.

Children
No Data