Is there an easy way to run code in sugar?

Hi,  It seems like it takes longer to develop with sugarCRM than just making a application from scratch.  Are there ways of running groups of code without needing to rebuild the application and clicking around to see if something as taken effect?  For example if I am using the beanfactory class to get an existing record with an specific ID can I echo that out to the console?

Best Regards

James Palmisano

  • Hi James,

    For debugging and testing code it is recommended to use custom EntryPoints: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Entry_Points/C…

    EntryPoints allow you to write and test code without the necessity of repairing and rebuilding the application 24/7. EntryPoints are executed using the browser as explained at the link above, so you can just print your variables in the browser using echo's in PHP inside the EntryPoint. For printing objects or arrays you can just use the PHP var_dump function.

    Although printing variables can be useful, I just recommend you to use an IDE like PhpStorm to develop and a debugger tool like XDebug so you can make code stops using breakpoints. This way you can check each moment the values of the defined variables all along your code.

    Hope that helps,

    David.

  • A couple of other thoughts...

    Logic hooks allow you to run arbitrary PHP code and can be applied without requiring a rebuild (although, best practice is to use logic hook extension to define it). Anyhow, that's another approach. If you wish to output data to the log file, you can always do so via the standard Sugar logging capabilities, as described here:

    Angel's Blog: SugarCRM Troubleshooting 101: Quick and Easy Custom Logs

    The type of code is also important. Sugar 7 uses a lot of JavaScript code and you can run a lot of prototype code directly within the JavaScript console in Chrome or your browser of choice. That would allow you to instantiate SugarBeans and a wide variety of things, all without having to rebuild. The JavaScript also offers ways to output info to the log, although it goes to the console, by simply using console.log('your message') and using "debugger" also comes in handy.

    In short, there are different ways to run prototypes and your options will vary depending on the type of code you are wanting to introduce.