6

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?

layman99
  • 61
  • 1
  • 3
  • Upgrade to the latest version of sugar and file type fields are included out of the box in studio or module builder. – Andy Main May 20 '11 at 09:25
  • looking to do the same thing and in the latest version there is not a file field – cuzzea Nov 08 '11 at 15:52
  • only available in commercial version, not in open source version. for open source version, please have a look of this one: http://www.sugarforge.org/projects/enhancedstudio/ – Leon Jun 19 '12 at 06:50

2 Answers2

2

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!

daniloaz
  • 469
  • 1
  • 4
  • 13
1

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.

frosty
  • 769
  • 6
  • 18