Results 1 to 10 of 10

Thread: Linked Fields?

  1. #1
    Rift is offline Member
    Join Date
    Feb 2008
    Posts
    7

    Default Linked Fields?

    Hi There

    I'm am in the middle of adapting sugar to be a replacement for a excel spreadsheet our sales team is currently using. One of my aims of doing this was to keep data entry down to a minimum therefor It would be great to automatically fill in fields based on another field. While I can't see a built in way of doing this I can see an example of this already in the form of the "Sales Stage" and "Probability" fields in the "Opportunities" Module.

    I have tried cloning these fields but have been able to duplicate the link between these fields. So was wondering if there was a way of doing this manually either by editing code or the database.

    Any help would be appreciated.

    Info (Not sure on all the versions but the site works fine)

    OS: Debian
    Sugar: Version 5.0.0 (Build 3095)
    Webserver: Apache
    PHP Version: 4 or 5

  2. #2
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: Linked Fields?

    look at this thread http://www.sugarcrm.com/forums/showt...=related+field

    it has the same subject

  3. #3
    Rift is offline Member
    Join Date
    Feb 2008
    Posts
    7

    Default Re: Linked Fields?

    Thanks for that kuske.

    It certainly seems a good place to start although the link refers to changes much more complex than what I had in mind. I should have been more specific from the start. Basically I want to have an integer field that is automatically filled based on a dropdown field selection, Kind of like how the "Sales Stage" and "probability" work now.

  4. #4
    Rift is offline Member
    Join Date
    Feb 2008
    Posts
    7

    Default Re: Linked Fields?

    In my hunt to track this down I went back to the source and checked through the sugar files for the script that controls the percentage value based on the sales stage. Unfortunately though I have found several files referring to a PROBABILITY_SCRIPT I am unable to actually find the actual script itself....anybody got any idea where I should start looking?

  5. #5
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: Linked Fields?

    Quote Originally Posted by Rift
    In my hunt to track this down I went back to the source and checked through the sugar files for the script that controls the percentage value based on the sales stage. Unfortunately though I have found several files referring to a PROBABILITY_SCRIPT I am unable to actually find the actual script itself....anybody got any idea where I should start looking?
    Hi Rift,
    here is what I've found:
    <sugar-root>/modules/Opportunities/metadata/editviewdefs.php (line 42):
    Code:
     'javascript' => '{$PROBABILITY_SCRIPT}',
    <sugar-root>/modules/Opportunities/views/view.edit.php (line 63):
    Code:
    $probability_script=<<<EOQ
     <script>
     prob_array = $prob_array;
     document.getElementsByName('sales_stage')[0].onchange = function() {
       if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && prob_array[document.getElementsByName('sales_stage')[0].value]) {
    	document.getElementsByName('probability')[0].value = prob_array[document.getElementsByName('sales_stage')[0].value];
       } 
      };
     $prePopProb
     </script>
    EOQ;
    	 
    	 $this->ss->assign('PROBABILITY_SCRIPT', $probability_script);
    Hope that helps
    What do you think the cookie monster eats ?

  6. #6
    Rift is offline Member
    Join Date
    Feb 2008
    Posts
    7

    Default Re: Linked Fields?

    Sorry for the long delay in reply as my project got sidelined for a while.

    Thx a lot DragonflyMaster! I should hopefully be able to hack something together from that!
    Last edited by Rift; 2008-03-10 at 04:53 PM.

  7. #7
    Rift is offline Member
    Join Date
    Feb 2008
    Posts
    7

    Default Re: Linked Fields?

    Due to my near complete lack of experience with JS i seem to be encountering problems

    I am trying to create an integer field called deposit that autofills depending on what is selected in the sales stage.

    I have created a dropdown called Deposit_autofil (which is essentially a duplicate of the sales_probability_dom
    I have created an integer fields called deposit1_c

    I have ammended <sugar-root>/modules/Opportunities/views/view.edit.php as follows

    Code:
    require_once('include/MVC/View/views/view.edit.php');
    
    class OpportunitiesViewEdit extends ViewEdit {
    
            function OpportunitiesViewEdit(){
                    parent::ViewEdit();
                    $this->useForSubpanel = true;
            }
    
            function display() {
                    global $app_list_strings;
                    $json = getJSONobj();
                    $Dep_array = $json->encode($app_list_strings['Deposit_autofil']);
                    $prob_array = $json->encode($app_list_strings['sales_probability_dom']);
                    $prePopProb = '';
                    $prePopDep = '';
                    if(empty($this->bean->id)) $prePopProb = 'document.getElementsByName(\'sales_stage\')[0].onchange();';
                    if(empty($this->bean->id)) $prePopDep = 'document.getElementsByName(\'sales_stage\')[0].onchange();';
    
    $probability_script=<<<EOQ
            <script>
            prob_array = $prob_array;
            document.getElementsByName('sales_stage')[0].onchange = function() {
                            if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && prob_array[document.getElementsByName('sales_stage')$
                                    document.getElementsByName('probability')[0].value = prob_array[document.getElementsByName('sales_stage')[0].value];
                            }
                    };
            $prePopProb
            </script>
    EOQ;
    
                $this->ss->assign('PROBABILITY_SCRIPT', $probability_script);
    
    $deposit_script=<<<EOQ
            <script>
            dep_array = $Dep_array;
    document.getElementsByName('sales_stage')[0].onchange = function() {
                            if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && dep_array[document.getElementsByName('sales_stage')$
                                    document.getElementsByName('deposit1_c')[0].value = dep_array[document.getElementsByName('sales_stage')[0].value];
                            }
                    };
            $prePopDep
            </script>
    EOQ;
    
                $this->ss->assign('DEPOSIT_SCRIPT', $deposit_script);
                    parent::display();
            }
    }
    ?>
    And ammended <sugar-root>/modules/Opportunities/metadata/editviewdefs.php like this

    Code:
    $viewdefs['Opportunities']['EditView'] = array(
        'templateMeta' => array('maxColumns' => '2',
                                'widths' => array(
                                                array('label' => '10', 'field' => '30'),
                                                array('label' => '10', 'field' => '30')
                                                ),
        'javascript' => '{$PROBABILITY_SCRIPT}',
        'javascript' => '{$DEPOSIT_SCRIPT}',
    ),
     'panels' =>array (
      'default' =>
      array (
    
        array (
          array('name'=>'name', 'displayParams'=>array('required'=>true)),
          'currency_id',
        ),
    
        array (
          'account_name',
          array( 'name'=>'amount','displayParams'=>array('required'=>true)),
        ),
    
        array (
          'opportunity_type',
          array('name'=>'date_closed', 'displayParams'=>array('required'=>true)),
        ),
    
        array (
          'lead_source',
          'next_step',
        ),
    
        array (
          'campaign_name',
        ),
    
        array (
    
    
    
            array('name'=>'sales_stage', 'displayParams'=>array('required'=>true)),
        ),
    
        array (
          'assigned_user_name',
          'probability',
          'deposit1_c',
        ),
    
           array (
          'description',
        ),
      ),
    )
    
    
    );
    ?>
    Nothing seems to be broken but my field deposit field in the edit view still dosnt autofill.....I imagine its due to some completely obvious idiotic mistake so feel free to mock but any help would be greatly appreciated.
    Last edited by Rift; 2008-03-11 at 11:15 AM.

  8. #8
    Rift is offline Member
    Join Date
    Feb 2008
    Posts
    7

    Default Re: Linked Fields?

    Paging all JS Guru's.....

  9. #9
    Rift is offline Member
    Join Date
    Feb 2008
    Posts
    7

    Default Re: Linked Fields?

    *batters eyelids* Pretty Please

  10. #10
    enigma is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    between 1's and 0's
    Posts
    39

    Default Re: Linked Fields?

    in your editviewdefs.php

    instead of doing:
    PHP Code:
    'javascript' => '{$PROBABILITY_SCRIPT}',
        
    'javascript' => '{$DEPOSIT_SCRIPT}'
    replace it with:
    PHP Code:
    'javascript' => '{$PROBABILITY_SCRIPT} {$DEPOSIT_SCRIPT}'

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 2007-02-05, 09:43 PM
  2. Replies: 1
    Last Post: 2006-09-11, 03:38 PM
  3. Adding Custom Fields to a layout (3.5.1)
    By pSouper in forum Help
    Replies: 3
    Last Post: 2006-07-09, 02:10 PM
  4. new added fields don't appear
    By snue in forum Feature Requests
    Replies: 0
    Last Post: 2006-05-08, 08:19 AM
  5. Linked fields.
    By mbro in forum Developer Help
    Replies: 2
    Last Post: 2005-05-16, 09:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •