Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Non Editable Custom Fields

  1. #1
    whitewidow is offline Sugar Community Member
    Join Date
    Jun 2010
    Posts
    68

    Default Non Editable Custom Fields

    Hi all,

    Hopefully someone can help me with a little problem I having with project tasks.

    I have created some hooks for various modules in my sugar install:

    Cases
    Projects
    Project tasks

    The hooks are pretty much identical with the exception of the paths to the modules and field name etc

    BUT

    for some reason I cannot get it to work properly for project tasks.

    I do not want the custom field to be editable by the users so only added the field to the DetailView and not the EditView for each module. This works fine for Cases and Projects but for some reason will not insert a record for Project Tasks. If I add the custom field to the EditView in project tasks it inserts the record but if the field is removed from the EditView in project tasks, the record for that field is blank.

    So, I have 2 questions:

    1. Can I make the custom field non-editable? If so, how?
    2. If not, can anyone advise why it fails to insert a record for Project tasks.

    I am using Sugar 6.0.2

    Your help much appreciated

  2. #2
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Non Editable Custom Fields

    You can make the field disabled by going into the editviewdefs.php and inputting a customCode segment in the definition, however you shouldn't have to. Mind posting your code and letting us know which field is blank?
    Robert Beckman
    Software Engineer
    Mirth Corporation

  3. #3
    whitewidow is offline Sugar Community Member
    Join Date
    Jun 2010
    Posts
    68

    Default Re: Non Editable Custom Fields

    Hi Robert,

    Thanks for your reply. Where can I find the editviewdefs.php file?

    Ideally I want my custom field to display in the same way that the case ID auto number field does e.g. When entering a new case the field is shown but the user cannot enter a value into it. Then upon saving the reference number is generated and stored.

    I have put this hook in place to fill out the auto value but like I said, for some reason it only works when the field is added to both the Edit & Detail views. For some reason it works fine for cases though.

    This is the Add_Code_Hook.php file:

    PHP Code:
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    class 
    add_code
    {        
        const 
    CODE_PREFIX "VSPT";            // Prefix (ie. LD represents the Leads prefix)
        
    const CODE_SEPARATOR "-";            // Character(s) separating the prefix and the code
        
    const MIN_CODE_LENGTH 4;             // e.g. 0001, 0002, etc; used to dictate padding
        
    const DATE_FORMAT "y";            // Date format string for part of the prefix (e.g. "y" = 09 in LD09-)
        
    const CUSTOM_FIELD "project_task_auto_id_c";    // Custom field to store the code in
        
    const CUSTOM_TABLE "project_task_cstm";     // Custom table where the custom field is located
        
        
    function add_code(&$bean$event$arguments)
        {
            
    $db =  DBManagerFactory::getInstance();
            
            
    // Create complete prefix for the code (e.g. LD09-)
            
    $prefix self::CODE_PREFIX.date(self::DATE_FORMAT).self::CODE_SEPARATOR;
            
            
    // Get the starting position for the SUBSTR call in the query
            
    $prefix_len strlen($prefix) + 1;
            
            
    $query "SELECT CAST(SUBSTR(".self::CUSTOM_FIELD.", $prefix_len) AS UNSIGNED) as ".self::CUSTOM_FIELD." FROM ".self::CUSTOM_TABLE.
                      WHERE ("
    .self::CUSTOM_FIELD." <> '' OR ".self::CUSTOM_FIELD." IS NOT NULL)
                      ORDER BY CAST(SUBSTR("
    .self::CUSTOM_FIELD.", $prefix_len) AS UNSIGNED) 
                      DESC 
                      LIMIT 1"
    ;
            
            
    $result $db->query($querytrue);
            
    $row $db->fetchByAssoc($result);
            
            
    // Increment the highest code by 1 and pad if necessary
            
    $code $row[self::CUSTOM_FIELD] + 1;
            
    $code str_pad($codeself::MIN_CODE_LENGTH"0"STR_PAD_LEFT);
            
            
    // Put it all together        
            
    $new_code $prefix.$code;
            
            
    // Update the record that was just saved
            
    $update_query "UPDATE ".self::CUSTOM_TABLE." SET ".self::CUSTOM_FIELD." = '$new_code'
                             WHERE id_c = '{$bean->id}' AND ("
    .self::CUSTOM_FIELD." = '' or ".self::CUSTOM_FIELD." IS NULL)";
                             
            
    $db->query($update_querytrue);
        }

    And this is the Logic_Hooks.php file:

    PHP Code:
        $hook_version 1
        
    $hook_array = Array(); 
        
        
    $hook_array['after_save'] = Array(); 
        
    $hook_array['after_save'][] = Array(1'add_code''custom/modules/ProjectTask/add_code_hook.php','add_code''add_code'); 
    My perfect solution to this would be to have the field displayed on both the Edit & Detail views but to have it non-editiable on the Edit View (With the word AUTO in the field) and to display the generated number in the Detail View. Obviously once the record has been generated I don't want it to be editable.

    Cheers

  4. #4
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Default Re: Non Editable Custom Fields

    add the field to the editview, then inside editview.php, on field definition array add the value

    PHP Code:
    'customCode' => 'auto' 
    this will override the default print out of field on screen and will just print out word auto. You can enter there any html.

    upgrade safe way copy/change editview in custom/modules/moduleName/metadata/editview.php
    CRM Software Engineer
    Eontek - www.eontek.rs

  5. #5
    whitewidow is offline Sugar Community Member
    Join Date
    Jun 2010
    Posts
    68

    Default Re: Non Editable Custom Fields

    Hi and thanks for your reply.

    Will the user still be able to overwrite this auto value in EditView though?

    Thanks

  6. #6
    whitewidow is offline Sugar Community Member
    Join Date
    Jun 2010
    Posts
    68

    Default Re: Non Editable Custom Fields

    One other thing, which EditView.php file does this need to be added to as there are loads of them?

    Thanks

  7. #7
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Default Re: Non Editable Custom Fields

    no, user will see only auto instead of the value, and use before-save logic hook to assign the value for the field to be writen to the database. I am refering to the editview.php file that is located inside the module you wish to implement this (modules/ProjectTask/metadata copy over to custom/modules/ProjectTask/metadata).

    What you get by this is, when user makes new record he will see value = auto, but in before-save logic hook you will assign real value to the field and save it inside the db.

    Take a look:

    http://www.eontek.rs/sugarcrm/logic-hooks-in-sugarcrm/
    CRM Software Engineer
    Eontek - www.eontek.rs

  8. #8
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Non Editable Custom Fields

    *editviewdefs.php

    and yes, you'll want to copy editviewdefs.php from modules/(module_name)/metadata to custom/modules/(module_name)/metadata if its not already in the custom directory.

    and a better custom code solution is the following:
    PHP Code:
    'customCode' => '{$fields.project_task_auto_id_c.value}<input disabled id="project_task_auto_id_c" name="project_task_auto_id_c" size="25" maxlength="25" type="text" value="{$fields.project_task_auto_id_c.value}">'
    This means you don't need to write an extra logic hook and the user will still actually be able to see the value but not able to edit it.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  9. #9
    whitewidow is offline Sugar Community Member
    Join Date
    Jun 2010
    Posts
    68

    Default Re: Non Editable Custom Fields

    Hi all and thanks for your replies. I have been trying to get this to work but so far have failed.

    Can someone tell me, where it says "customCode" am I supposed to replace this with something else i.e. My field name? Also where in the editviewdefs.php do I add it?

    I am trying to add this to the Bugs module and have edited the 'editviewdefs.php' in this location: custom\modules\Bugs\metadata. Is this correct or should I be editing another file?

    My code looks like this at present and I have also tried the alternative code suggested by robertbmirth but I can't get either to work. I am guessing I have added the code in the worng place?

    PHP Code:
    <?php
    $viewdefs 
    ['Bugs'] = 
    array (
      
    'EditView' => 
      array (
        
    'templateMeta' => 
        array (
          
    'form' => 
          array (
            
    'hidden' => 
            array (
              
    => '<input type="hidden" name="account_id" value="{$smarty.request.account_id}">',
              
    => '<input type="hidden" name="contact_id" value="{$smarty.request.contact_id}">',
            ),
          ),
          
    'maxColumns' => '2',
          
    'widths' => 
          array (
            
    => 
            array (
              
    'label' => '10',
              
    'field' => '30',
            ),
            
    => 
            array (
              
    'label' => '10',
              
    'field' => '30',
            ),
          ),
          
    'useTabs' => false,
        ),
        
    'panels' => 
        array (
          
    'lbl_bug_information' => 
          array (
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'bugs_auto_id_c',
                
    'label' => 'LBL_BUGS_AUTO_ID',
                
    'customCode' => 'AUTO',
              ),
              
    => '',
            ),
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'name',
                
    'displayParams' => 
                array (
                  
    'size' => 60,
                  
    'required' => true,
                ),
              ),
            ),
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'priority',
                
    'comment' => 'An indication of the priorty of the issue',
                
    'label' => 'LBL_PRIORITY',
              ),
              
    => 
              array (
                
    'name' => 'type',
                
    'comment' => 'The type of issue (ex: issue, feature)',
                
    'label' => 'LBL_TYPE',
              ),
            ),
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'source',
                
    'comment' => 'An indicator of how the bug was entered (ex: via web, email, etc.)',
                
    'label' => 'LBL_SOURCE',
              ),
              
    => 
              array (
                
    'name' => 'status',
                
    'comment' => 'The status of the issue',
                
    'label' => 'LBL_STATUS',
              ),
            ),
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'product_category',
                
    'comment' => 'Where the bug was discovered (ex: Accounts, Contacts, Leads)',
                
    'label' => 'LBL_PRODUCT_CATEGORY',
              ),
              
    => 
              array (
                
    'name' => 'resolution',
                
    'comment' => 'An indication of how the issue was resolved',
                
    'label' => 'LBL_RESOLUTION',
              ),
            ),
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'found_in_release',
                
    'comment' => 'The software or service release that manifested the bug',
                
    'studio' => 
                array (
                  
    'fields' => 'false',
                  
    'listview' => false,
                  
    'wirelesslistview' => false,
                ),
                
    'label' => 'LBL_FOUND_IN_RELEASE',
              ),
              
    => 
              array (
                
    'name' => 'fixed_in_release',
                
    'comment' => 'The software or service release that corrected the bug',
                
    'studio' => 
                array (
                  
    'fields' => 'false',
                  
    'listview' => false,
                  
    'wirelesslistview' => false,
                ),
                
    'label' => 'LBL_FIXED_IN_RELEASE',
              ),
            ),
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'description',
                
    'nl2br' => true,
              ),
            ),
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'work_log',
                
    'nl2br' => true,
              ),
            ),
          ),
          
    'LBL_PANEL_ASSIGNMENT' => 
          array (
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'assigned_user_name',
                
    'label' => 'LBL_ASSIGNED_TO_NAME',
              ),
            ),
          ),
        ),
      ),
    );
    ?>
    Your help would be greatly appreciated

  10. #10
    whitewidow is offline Sugar Community Member
    Join Date
    Jun 2010
    Posts
    68

    Default Re: Non Editable Custom Fields

    Just wondered if anyone had any idea about this at all?

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dev Tool Kit - toggle editable fields
    By anatal52 in forum Developer Help
    Replies: 0
    Last Post: 2010-10-08, 05:42 PM
  2. Replies: 2
    Last Post: 2010-09-02, 10:01 PM
  3. Custom Fields Not Editable
    By selvin in forum Help
    Replies: 4
    Last Post: 2008-02-04, 01:42 PM
  4. Replies: 2
    Last Post: 2007-06-18, 07:34 PM
  5. Replies: 0
    Last Post: 2006-12-20, 11:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •