Categories
ERP Customization

Adding quick create button to SuiteCRM AOS Products module popup view

The popup view usually serves the purpose of choosing a related record. Oftentimes, the user will realize that the desired record is not in the database and has to be created. This is where quick create buttons make the process easier by allowing the user to create a new record from within the popup view, without the need to close the popup and navigate to another module.

Unfortunately, quick create buttons are not present by default in every module. In some modules these can be added rather easily by customizing popupdefs.php. Such solution requires the modified module to have an appropriate FormBase class, which non of the AOS modules have. In this post I’m going to describe how to add the quick create button to AOS Products module popup view. Such customization is particularly useful if your users are creating quotes and need the ability to create new products on the fly.

Editing Products’ popup defs

To begin with, the following change has to be made to the AOS Products’ popupdefs.php file just after searchInput (do it custom folder):

'create' =>
  array('formBase' => 'AOS_ProductsFormBase.php',
    'formBaseClass' => 'AOS_ProductsFormBase',
    'getFormBodyParams' => array('','','AOS_Productssave'),
    'createButton' => 'Create product' //label
),

Adding AOS Products FormBase

While the snippet above would do the job just fine for most modules, since AOS Products module doesn’t have it’s own FormBase class, you will get an error (causing a white screen) whenever opening the popup. To solve that problem, it’s necessary to create one in AOS_ProductsFormBase.php. It turns out that the only function that has to be implemented inside it in order for the described solution to work is handleSave:

<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/SugarObjects/forms/FormBase.php');

class AOS_ProductsFormBase extends FormBase
{
   var $moduleName = 'AOS_Products';
   var $objectName = 'AOS_Products';

   function handleSave($prefix, $redirect = true, $useRequired = false)
   {
     require_once('include/formbase.php');
     $focus = new AOS_Products();
     $focus = populateFromPost($prefix, $focus);
     $focus->save();
   }
}

The file has to be created in both the main folder of AOS_Products module as well as in `custom/modules/AOS_Products` folder. All you have to do next is go to the admin panel and perform Quick Repair and Rebuild. Now after clicking on Create Product button, the user should see the form allowing them to add new product record. You can customize the form in Studio (Quick Create view).

Leave a Reply

Your email address will not be published. Required fields are marked *