Calculate field with line breaks

Hi, I'm trying to create a calculated/concatenated field that pulls fields from related records and would like to have line breaks between the field values, not spaces? As an example, I'm trying to pull the contacts company address fields and the contacts phone numbers into a text area field, I'd like line breaks between each line of the address and the phone numbers to be on seperate lines

I have tried using \n\r and \\n\\r in my calculated concat field but it treats them as a string. If it is not possible in a TextArea field, is it possible in an HTML  field and last resort I suppose would be an aftersave logichook

Thanks for any assistance you can give me

Parents
  • Hi Rob,

    Unfortunately, there is not currently a way to use Sugar Logic to add a newline into a field, and an HTML field cannot use calculated formulas. A logic hook is going to be your best bet. Here is how I got it working in a logic hook:

    // custom/modules/Accounts/logic_hooks.php
    <?php
    $hook_version = 1;
    $hook_array = Array();
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'Store values', 'custom/modules/Accounts/My_Logic_Hooks.php', 'My_Logic_Hooks', 'before_save_method' );
    
    // custom/modules/Accounts/My_Logic_Hooks.php
    <?php 
    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    class My_Logic_Hooks {
      function before_save_method($bean, $event, $arguments) {
      $bean->test_calc_newline_c = $bean->annual_revenue . "\r" . $bean->name . "\n" . $bean->account_type; // both of these worked
      }
    }
    

    I hope that helps!

    -Alan

  • Hi Rob,

    You can check out our documentation on Fetching Relationships with SugarBean objects. For your example, I would do something like this:

    if($bean->load_relationship('contacts_mba_mba_detail_1_c')) {
      $relatedBeans = $bean->$link->getBeans();
      foreach($relatedBeans as $relatedBean) {
        $c_id = $relatedBean->id;
        // The rest of your code can go here
      }
    }
    

    The exact name of the relationship may vary, so you will have to verify that in order for this to work. Let me know if you have any questions!

    -Alan

  • Hey Alan, thanks for all you help and the link to your online resources, once I found the proper relationship name and swapped out the $link variable, all good

    Cheers

Reply Children
No Data