Add create to Documents popup

Hi,
is it possible to add the ā€œcreateā€ button in the document search popup?
The one that opens when there is a relate field in a moduleā€¦
Thanks so much!

Have a peek here

In short;

  1. Copy the vardef to custom
  2. Add a line within the vardef for the custom element
  3. QR&R and see if it works

Ok, thank you!
But where (how) can i find the parameters for the documents?

EDIT

popupdefs > I add:

$popupMeta = array(
    'moduleMain' => 'Documents',
    'varName' => 'DOCUMENTS',
    'orderBy' => 'name',
    'whereClauses' => array(
    ),
    'searchInputs' => array(
    ),
	
	'create' => array (
        'formBase' => 'DocumentFormBase.php',
        'formBaseClass' => 'DocumentFormBase',
        'getFormBodyParams' => array(
            0 => '',
            1 => '',
            2 => 'DocumentSave',
          ),
        'createButton' => $mod_strings['LBL_NEW_FORM_TITLE'],
    ),

    'searchdefs' => array(
    ),
    'listviewdefs' => array(
    ),
);

custom > modules > Documents > DocumentFormBase,php
I add:

<?php

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

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

class DocumentFormBase extends FormBase {

var $moduleName = 'Documents';
var $objectName = 'Document';

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

?>

but this is not working.
Iā€™m getting a white popup that could indicate a php error ā€¦
but it might be a little different for Documents ā€¦ I hope in a suggestion

Iā€™m not sure if this is the error but try by using the real Module name on it
For example instead of using ā€˜DocumentFormBase.phpā€™ use 'DocumentsFormBase.php

That should be the same for all the sections were you call the module name. Then do a QR&R to see if it works.

Thanks,

BrozTechnologies

So, if I use Documents everywhere, it doesnā€™t work againā€¦
I think I also tried various combinationsā€¦

Hi,
I have made some progress. I agree because it could be useful to others.

popupdefs.php:

<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}
$popupMeta = array(
    'moduleMain' => 'Documents',
    'varName' => 'DOCUMENTS',
    'orderBy' => 'name',
    'whereClauses' => array(
    ),
    'searchInputs' => array(
    ),
	// Add create
	'create' => array (
        'formBase' => 'DocumentsFormBase.php',
        'formBaseClass' => 'DocumentsFormBase',
        'getFormBodyParams' => array(
            0 => '',
            1 => '',
            2 => 'DocumentSave',
          ),
        'createButton' => $mod_strings['LBL_NEW_FORM_TITLE'],
    ),
    'searchdefs' => array(
    ),
    'listviewdefs' => array(
    ),
);

DocumentsFormBase.php:
please note that this file works if it is in the module directory, if it is in custom it doesnā€™t work (even if I put the address custom / modules / Documents / DocumentsFormBase.php in popupdefs.php)

<?php

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

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

class DocumentsFormBase extends FormBase {

var $moduleName = 'Documents';
var $objectName = 'Document';

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

?>

At this point, the popup is displayed, the creation form is displayed in the popup and, apparently, the saving is closed.

But:

  • the relationship with the document is not maintained in my custom module
  • if I try to open the document from Documents, I read: ā€œThis document is missing a file, most likely due to an error during upload. Please retry uploading the file or contact your administrator.ā€

In the log file I find the following error:
ā€œSugarBean.load_relationships, failed Loading relationship (related_doc_id)ā€
And I donā€™t see files in the Uploads folder

Any suggestions? Thank you very much

I followed this sample to add it to a custom module. Never done it with the Documents module. https://community.sugarcrm.com/thread/21605

Yes, I had seen the example.
It seems that it only saves some fields in db but it doesnā€™t upload and doesnā€™t write in ā€œdocuments_revisionsā€ table (thatā€™s why I receive the error reported in the previous post).

So, it isnā€™t executing the save () function in Document.php here:
$focus->save();

Here, two popup screenshot:
EDIT

AFTER SAVE

Any suggestions are very welcome.

So, this method works if I have standard fields but it doesnā€™t apply to document uploads and revisions.

But I havenā€™t given up yet and I have a question:

  • when is the handleSave function executed?
    I canā€™t retrieve the item id before save (), is that correct?

In theory, I should trigger the upload before the save and immediately after save the revision and align the file name with the revision id ā€¦
at the moment I canā€™t think of an easier way ā€¦

Hello everyone,

hopes it give you all an insight. I was able to create a ā€˜createā€™ function in poupdefs.
I just copy the DocumentFormBase and put it in default module php at :
ā€œmodules<module name><module name>.phpā€

before :

<?php
/**
 *
 * SugarCRM Community Edition is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
 *
 * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
 * Copyright (C) 2011 - 2018 SalesAgility Ltd.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for technical reasons, the Appropriate Legal Notices must
 * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 */
 
 
 class DPL_Daftar_Pelanggan extends Basic
 {
     public $new_schema = true;
     public $module_dir = 'DPL_Daftar_Pelanggan';
     public $object_name = 'DPL_Daftar_Pelanggan';
     public $table_name = 'dpl_daftar_pelanggan';
     public $importable = true;
 
     public $id;
     public $name;
     public $date_entered;
     public $date_modified;
     public $modified_user_id;
     public $modified_by_name;
     public $created_by;
     public $created_by_name;
     public $description;
     public $deleted;
     public $created_by_link;
     public $modified_user_link;
     public $assigned_user_id;
     public $assigned_user_name;
     public $assigned_user_link;
     public $SecurityGroups;
 	
     public function bean_implements($interface)
     {
         switch($interface)
         {
             case 'ACL':
                 return true;
         }
 
         return false;
     }
 	
 }

after

 <?php
 /**
  *
  * SugarCRM Community Edition is a customer relationship management program developed by
  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
  *
  * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
  * Copyright (C) 2011 - 2018 SalesAgility Ltd.
  *
  * This program is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Affero General Public License version 3 as published by the
  * Free Software Foundation with the addition of the following permission added
  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  *
  * This program is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  * details.
  *
  * You should have received a copy of the GNU Affero General Public License along with
  * this program; if not, see http://www.gnu.org/licenses or write to the Free
  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301 USA.
  *
  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  *
  * The interactive user interfaces in modified source and object code versions
  * of this program must display Appropriate Legal Notices, as required under
  * Section 5 of the GNU Affero General Public License version 3.
  *
  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  * these Appropriate Legal Notices must retain the display of the "Powered by
  * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  */
 
 
 class DPL_Daftar_Pelanggan extends Basic
 {
     public $new_schema = true;
     public $module_dir = 'DPL_Daftar_Pelanggan';
     public $object_name = 'DPL_Daftar_Pelanggan';
     public $table_name = 'dpl_daftar_pelanggan';
     public $importable = true;
 
     public $id;
     public $name;
     public $date_entered;
     public $date_modified;
     public $modified_user_id;
     public $modified_by_name;
     public $created_by;
     public $created_by_name;
     public $description;
     public $deleted;
     public $created_by_link;
     public $modified_user_link;
     public $assigned_user_id;
     public $assigned_user_name;
     public $assigned_user_link;
     public $SecurityGroups;
 	
     public function bean_implements($interface)
     {
         switch($interface)
         {
             case 'ACL':
                 return true;
         }
 
         return false;
     }
 	
 }
 
 require_once('include/SugarObjects/forms/FormBase.php');
 
 class DPL_Daftar_Pelanggan_FormBase extends FormBase {
 
 var $moduleName = 'DPL_Daftar_Pelanggan';
 var $objectName = 'DPL_Daftar_Pelanggan';
 
     function handleSave($prefix, $redirect=true, $useRequired=false){
         require_once('include/formbase.php');
         $focus = new DPL_Daftar_Pelanggan();
         $focus = populateFromPost($prefix, $focus);
         $focus->save();
     }
 }
2 Likes