Auto populate note / task name with Opportunity name

When creating a note / task from a subpanel in Opportunities, is it possible to pre-populate the name of note / task with the name of the opportunity? This needs to work on mobile as well, so I can't do it in javascript (I don't think at least). If I make the name field a calculated field to be a related($opportunities, "name"), it works after the save. I need the user to be able to see it and change it if necessary. So essentially I need a way to type in the name for the user. Is this possible? I've spent a while trying a few things, nothing has been successful. 

  • Hi Ryan Horton 

    It is possible to make it work even on mobile.

    You have to:

    • create the field opp_name in Tasks and Notes
    • Configure the attribute populate_list in the field definition of tasks and notes at module Opportunities (take a look at the field contacts in the vardefs of Opportunities module)
    • Define a SugarLogic formula for calculating the name of Task and Note accordingly

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • I've taken these steps and the web works, but the mobile app does not. Does something else need to be done for this to work on mobile? 

    The field I created was parent_name. My populate list has 'name' => 'parent_name_c'. 'name' in Task / Notes has a calculation of simply $parent_name_c. This all work as expected in web.

    When on mobile a few odd things. parent_name_c isn't being populated in the edit view.

    When I added parent_name_c to the edit layout and went to deploy, I got the following message:

    Is there something I am missing?

  • Something I forgot to mention:

    You must add the field parent_name_c in the layout of mobile. Make it readonly at the begining to make sure it is properly populated and then make it not visible.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi Ryan Horton,

    I did something similiar with the Opportunity name some time ago.

    My scenario:

    On creating an Opportunity, a shortname of the linked account should be prefilled in the opps name field but let the user be able to add the name of the opportunity.

    It works like this:

    1.

    I placed this formula in the opps name field in studio, making sure it will be set regardless of the "short name" is given or not:

    ifElse(or(equal($name,"undefined - "),equal($name,"")),ifElse(greaterThan(strlen(related($accounts,"account_name_short_c")),0),concat(related($accounts,"account_name_short_c")," - "),""),$name)

    2. Do give the user access to the calculated field to alter the content I added this

    $dictionary['Opportunity']['fields']['name']['enforced'] = false;

    to

    custom/Extension/modules/Opportunities/Ext/Vardefs/sugarfield_name.php

    3. This may be optional but in some cases it appeared that the opps got the same name and the users complained about the appearing duplicate check so we turned it off for opps by creating a new file in vardefs:

    1.Create \custom\Extension\modules\Opportunities\Ext\Vardefs\sugarfield_cancel_duplicate_check.php (The name of this file can be changed to else as you wish). And add the following code.

    <?php
    $dictionary['Opportunity']['duplicate_check']['enabled']=false;
     ?>

    2.Do quick-repair & Rebuild.

    To be honest I have not tried if this works on mobile and are currently not able to do it quickly.

    Best regards

    Björn

  • Hi Björn Canales Pfisterer 

    This approach will not work on mobile, specially on offline mode.

    In order to make it work on mobile it is mandatory to calculate a field based on fields under the same module and all fields have to be published in the current view.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi André Lopes,

    good to know. Unfortunatelly I have no experience with this on mobile but hopefully it helps Ryan Horton to cover this part:

    I need the user to be able to see it and change it if necessary.

    Also the duplicate check hint might be usefull to ;-)

    Bests

    Björn

  • After setting the 'parent_name_c' field to readonly and adding it to the layout, it still isn't populating in mobile app or mobile web. I can't click in the field on the mobile so it seems that readonly works. If it matters, I am on 8.0.2.

  • Can you share the content of vardefs for tasks and notes link fields in Opportunities module and formula for field name on both Tasks and Notes modules?

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • custom/Extension/modules/Opportunities/Ext/Vardefs/populate_names_task_notes.php

    <?php

    $dictionary['Opportunity']['fields']['tasks']['populate_list'] = array('name' => 'parents_name_c');
    $dictionary['Opportunity']['fields']['notes']['populate_list'] = array('name' => 'parents_name_c');

    custom/Extension/modules/Notes/Ext/Vardefs/sugarfield_name.php

    <?php


    $dictionary['Note']['fields']['name']['audited'] = false;
    $dictionary['Note']['fields']['name']['massupdate'] = false;
    $dictionary['Note']['fields']['name']['comments'] = 'Name of the note';
    $dictionary['Note']['fields']['name']['importable'] = 'false';
    $dictionary['Note']['fields']['name']['duplicate_merge'] = 'disabled';
    $dictionary['Note']['fields']['name']['duplicate_merge_dom_value'] = 0;
    $dictionary['Note']['fields']['name']['merge_filter'] = 'disabled';
    $dictionary['Note']['fields']['name']['full_text_search'] = array(
    'enabled' => true,
    'boost' => '0.83',
    'searchable' => true,
    );
    $dictionary['Note']['fields']['name']['calculated'] = 'true';
    $dictionary['Note']['fields']['name']['formula'] = '$parents_name_c';
    $dictionary['Note']['fields']['name']['enforced'] = false;

    custom/Extension/modules/Tasks/Ext/Vardefs/sugarfield_name.php

    <?php


    $dictionary['Task']['fields']['name']['audited'] = false;
    $dictionary['Task']['fields']['name']['massupdate'] = false;
    $dictionary['Task']['fields']['name']['importable'] = 'false';
    $dictionary['Task']['fields']['name']['duplicate_merge'] = 'disabled';
    $dictionary['Task']['fields']['name']['duplicate_merge_dom_value'] = 0;
    $dictionary['Task']['fields']['name']['merge_filter'] = 'disabled';
    $dictionary['Task']['fields']['name']['unified_search'] = false;
    $dictionary['Task']['fields']['name']['full_text_search'] = array(
    'enabled' => true,
    'boost' => '1.45',
    'searchable' => true,
    );
    $dictionary['Task']['fields']['name']['calculated'] = 'true';
    $dictionary['Task']['fields']['name']['formula'] = '$parents_name_c';
    $dictionary['Task']['fields']['name']['enforced'] = false;

    custom/modules/Tasks/clients/mobile/views/edit/edit.php

    'fields' =>
       array(
          0 =>
             array(
                'name' => 'parents_name_c',
                'label' => 'LBL_PARENTS_NAME',
                'readonly' => true
             ),

    custom/modules/Notes/clients/mobile/views/edit/edit.php

    'fields' =>
       array(
          0 =>
             array(
                'name' => 'parents_name_c',
                'label' => 'LBL_PARENTS_NAME',
                'readonly' => true,
             ),

    Thanks for your help in this André Lopes

  • Can you confirm if new Task and Note are properly linked to the Opportunity after saving on both Sugar interface and mobile as well?

    André Lopes
    Lampada Global
    Skype: andre.lampada