Remove spaces in a string

I'm trying to change a record name in to a sting without spaces so I can use it as the first part of an email address. i.e. my record name is "Lost Profits LLC" I'd like to turn it into "lost_profits_llc" so find the spaces, if there are any and replace them with _

I can't find any suitable Sugar logic functions

Parents
  • Hi Howard,

    There is not a calculated field function that can do this. There are two possible custom code approaches that come to mind.

    1. Attached to this comment is an example Module Loader package I made back in 2017 that adds a replace() function to the instance. While the JavaScript part doesn't seem to be working well, the PHP part seems to work upon save in my recent test.

       Note that installing and uninstalling custom sugar logic functions can be tricky. If you install this, I recommend:

    • Run Repair and Rebuild
    • Run Rebuild Sugar Logic Functions
    • Clear browser data and "Hard Refresh and Clear Cache"

    2. A custom logic hook that runs when the record is saved can do this in the background using very similar code as the PHP portion of the attached package.

    Before you Uninstall a Module Loader package for custom Sugar Logic, you must make sure you remove any reference of that formula from calculated fields. If you do not, your instance will experience a system down 500 error and you will need your host (support) to fix the instance to restore access.

Reply
  • Hi Howard,

    There is not a calculated field function that can do this. There are two possible custom code approaches that come to mind.

    1. Attached to this comment is an example Module Loader package I made back in 2017 that adds a replace() function to the instance. While the JavaScript part doesn't seem to be working well, the PHP part seems to work upon save in my recent test.

       Note that installing and uninstalling custom sugar logic functions can be tricky. If you install this, I recommend:

    • Run Repair and Rebuild
    • Run Rebuild Sugar Logic Functions
    • Clear browser data and "Hard Refresh and Clear Cache"

    2. A custom logic hook that runs when the record is saved can do this in the background using very similar code as the PHP portion of the attached package.

    Before you Uninstall a Module Loader package for custom Sugar Logic, you must make sure you remove any reference of that formula from calculated fields. If you do not, your instance will experience a system down 500 error and you will need your host (support) to fix the instance to restore access.

Children
No Data