onclick selector of relate type


May I confirm in what file and location will I be able to see this so I can modify it? (please see attach screenshot).

I have done this previously by extending the Opportunities view.edit.php file (created in /custom/modules/Opportunities/view.edit.php) and then overriding the onclick function of the button. It may not be the most elegant solution, but it works for my purposes. Hopefully this will get you on the right path:

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');


class CustomOpportunitiesViewEdit extends OpportunitiesViewEdit {

	public function display()
        global $mod_strings;
        //javascript to make field mandatory
        $jsscript = <<<EOQ
                       $('#campaign_name').change(function() {
                            makerequired(); // onchange call function to mark the field required
                     function makerequired()
                        var campaign = $('#campaign_name').val(); // get current value of the field
                        if(campaign == 'Referral/Former Client'){ // check if it matches the condition: if true,
								$('#referral_source_c_label').html('{$mod_strings['LBL_REFERRAL_SOURCE']}: <font color="red">*</font>'); // with red * sign next to label
                                $('#referral_source_c_label').html('{$mod_strings['LBL_REFERRAL_SOURCE']}: '); // and give the normal label back
                    makerequired(); //Call on load when editing an preexisting record
					document.getElementById('btn_campaign_name').onclick = function()
						var popup_request_data = 
							'call_back_function' : 'set_returns',
							'form_name' : 'EditView',
							'field_to_name_array' : 
								'id' : 'id',
								'name' : 'name',
					open_popup('Campaigns', 600, 400, '', true, false, popup_request_data);
					function set_returns(popup_reply_data)
						var name_to_value_array = popup_reply_data.name_to_value_array;
						var id = name_to_value_array['id'];
						var name = name_to_value_array['name'];
						document.getElementById('campaign_name').value = name ;
						document.getElementById('campaign_id').value = id;
        echo $jsscript;     //echo the script


Good luck!

1 Like

Hi Rusty,

Thank you very much for your help!

I’ve spent a lot of time figuring this out but with your help it worked.

I really appreciate it!!! B) B) B)

Awesome! Glad it helped.


Do you have an idea on how/what file can I override the onclick function in the calendar?

Hi All,

Any idea please on how/what file can I override the onclick function of meeting in the calendar?

need some help on this please :unsure: :unsure: :unsure:


Any idea please