How to clean text with Logic Hook formula?

Hello!

Im newbie in Logic Hooks.

I want to write a Logic Hook int the Account module that clean inserted text data after saving.

In Excel I used the :

TRIM, CLEAN and PROPER functions like this:

=PROPER(TRIM(CLEAN(Text)))

The formula is removed the extra spaces and other fancy charaters, and converted the text (or name) to lowercase but the firs letter to uppercase.

How to achieve this functionality with formulas provided by Sugar. Are the formulas we can use in Logic Hook is equal with formulas we can use in Sugar Logic? If yes, than how to get this functionality?

Thanks for help!

Regards,

Arpad

Parents Reply
  • Hi Arpad

    Basically you need to define those functions if they are neither php or SugarCRM builtin functions.

    Then you can invoke them in order to modify some specific fields:

    <?php

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

    class logic_hooks_class {

      function after_save_method($bean, $event, $arguments {

      $fields_to_clean = array('first_name', 'last_name', 'description');

      foreach($fields_to_clean as $field) {

      $bean->$field = $this->clean_field($bean->$field);

      }

      }

      private function clean_field($value) {

      // do something

      }

    }

    ?>

    Chees

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

    Thank You for Your help, just created a Custom Logic Hook !

    Here it is, used to clean the company name from fancy characters and to standardise it:

    <?php
        class Clean
        {
            function CleanName($bean, $event, $arguments)
            {
               $companyname = $bean->name;
               $companyname = ucwords(strtolower(trim(str_replace('"',' ',$companyname))));
               
               $bean->name = $companyname;
            }

        }
    ?>