Popup Search Create or custom related modules

Hi all,
I’m trying to understand how to have the create button when trying to link a custom module record.

Just to be clear I’d like to have the same CREATE button you see on default modules (e.g. when selecting the CREATE ACCOUNT for a new contact you can create the account from scratch in the popup search).

Many Thanks!

Please try this one.

  • Adding this code to the module file: /custom/modules//metadata/popupdef.php
  • Create file On: /custom/modules//FormBase.php
        <?php
         require_once('include/SuiteObjects/forms/FormBase.php');

        class MyModuleFormBase extends FormBase {

              var $moduleName = 'MyModule';
              var $objectName = 'MyModule';

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

        }
        }

        ?>

After completing all things getting Quick Repair…

Thank You

Thanks Vijay, still wondering why it is not part of the standard UI popup management. :-/

BTW I failed to mention I’m already working on the SuiteCRM 8Beta.
Does the customisation still apply?
Thanks.

include/SuiteObjects doen’t exist.

require_once line should be

require_once 'include/SugarObjects/forms/FormBase.php';

Also I replaced the MeetingFormBase class with the minimum setup shown here and I was not able to get the feature to work.

The record is created however, the popup window doesn’t disappear, instead it shows values saved into the record as search parameters on the popup window with no search results.

I’ll try your formbase setup on another module to see if it is an issue with the meetings module.


So I’ve made my own FormBase file for product categories

<?php

require_once 'include/SugarObjects/forms/FormBase.php';

class AOS_Product_CategoryFormBase extends FormBase
{
    var $moduleName = 'AOS_Product_Categories';
    var $objectName = 'AOS_Product_Category';

    function handleSave($prefix, $redirect=true, $useRequired=false)
    {
        require_once 'include/formbase.php';
        //$focus = BeanFactory::newBean($moduleName); //@TODO figure out why this isn't working
        $focus new $moduleName();
        $focus = populateFromPost($prefix, $focus);
        $focus->save();

        if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
            $json = getJSONobj();
            echo $json->encode(array('status' => 'success', 'get' => ''));
            return null;
        }

        if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
            $urlData = array(
                "query" => true,
                "name" => $focus->name,
                "module" => $moduleName,
                'action' => 'Popup'
            );
            if (!empty($_POST['return_module'])) {
                $urlData['module'] = $_POST['return_module'];
            }
            if (!empty($_POST['return_action'])) {
                $urlData['action'] = $_POST['return_action'];
            }
            foreach (array('return_id', 'popup', 'create', 'to_pdf') as $var) {
                if (!empty($_POST[$var])) {
                    $urlData[$var] = $_POST[$var];
                }
            }
            header("Location: index.php?".http_build_query($urlData));
            return;
        }

        if ($redirect) {
            handleRedirect($return_id, $moduleName);
        } else {
            return $focus;
        }
    }
}

The extra parts not in @vijay1992 provided example was written to match the code found in AccountsFormBase and ContactsFormBase.

With these changes I am able to create a new Product Category from within the relate popup window, however it doesn’t close the popup window. One notable difference however is that this does return back a result in the list whereas the meeting module wasn’t in its popup window.