Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making a file type field in sugarcrm custom module

Tags:

sugarcrm

i have a custom module Sample Management. I want to create a file type field in editviewdef.php so that i can upload the file and download it from the detailed view whenever needed. Would anyone tell me the steps how to proceed for this task?

like image 588
layman99 Avatar asked Apr 05 '11 06:04

layman99


People also ask

How do I create a custom module in SugarCRM?

Creating New Modules Module Builder functionality is managed within the 'Developer Tools' section of Sugar's administration console. Upon selecting 'Module Builder', the user has the option of creating a "New Package".

Is SugarCRM customizable?

SugarCRM provides you with various tools to make our customizable CRM software your own. Create custom layouts, relationships, and fields – all of these without writing a line of code. Use Sugar Studio to customize your Sugar instance as well as the Self-service Portal.


2 Answers

If you are creating the module through Module Builder, just add 'file' => 1, to the 'templates' array in $config variable (config.php). Then you'll be able to add a new upload file field to your editviewdefs.php:

      1 =>
      array (
        'name' => 'uploadfile',
        'displayParams' =>
        array (
          'onchangeSetFileNameTo' => 'document_name',
        ),
      ),

Don't forget to add the form and javascript elements to the templateMeta array in editviewdefs.php:

  'form' =>
  array (
    'enctype' => 'multipart/form-data',
    'hidden' =>
    array (
    ),
  ),
  'javascript' => '<script type="text/javascript" src="include/javascript/popup_parent_helper.js?s={$SUGAR_VERSION}&c={$JS_CUSTOM_VERSION}"></script>
    <script type="text/javascript" src="include/javascript/sugar_grp_jsolait.js?s={$SUGAR_VERSION}&c={$JS_CUSTOM_VERSION}"></script>
    <script type="text/javascript" src="modules/Documents/documents.js?s={$SUGAR_VERSION}&c={$JS_CUSTOM_VERSION}"></script>',

You also need to add the uploadfile field to detailvidefs.php:

      1 =>
      array (
        'name' => 'uploadfile',
        'displayParams' =>
        array (
          'link' => 'uploadfile',
          'id' => 'id',
        ),
      ),

Hope this helps!

like image 69
daniloaz Avatar answered Oct 23 '22 22:10

daniloaz


What you need to do is create a custom SugarField type by:

  1. Creating a new folder with the name of the field type in include/SugarFields/Fields
  2. Within that folder, you need to create a .tpl file to describe how the field is setup for each view type (so you would have an EditView.tpl, DetailView.tpl, and any other views that you would be using that field for). I would look in the /include/SugarFields/Fields/Text for a good example of what tpls you should create.
  3. Create a new field with that type, or by using vardefs or the field_meta_data table (for custom fields) change the field type from it's existing type to your new type.

I can definitely verify that there is a file field type as of SugarCRM 6.4.1, once you define how the field is laid out, you should be able to use it seamlessly with the rest of the CRM.

like image 40
frosty Avatar answered Oct 23 '22 21:10

frosty