How to make Case description readonly after save?

How to make  Cases description readonly in editview after it has been save?

TIA,

Longki Dela Cruz

Parents
  • Roland Cadavos,

    I presume that you only want it to become read-only once it has been populated with something. There are a few ways that you can do this, with each option depending slightly on the version/edition of Sugar you are using and the exact rules that need to be enforced.

    However a base level resolution for this is to create a duplicate description field and make one a calculated field to copy the value of the other. You would then set dependencies so that the initial fields hides when the calculated one is populated with something, and use the same principal on the calculated field. This will make it look as if the field is suddenly becoming read-only, where in fact it is simply swapping the fields over.

    If you are looking for something more than this let me know.

Reply
  • Roland Cadavos,

    I presume that you only want it to become read-only once it has been populated with something. There are a few ways that you can do this, with each option depending slightly on the version/edition of Sugar you are using and the exact rules that need to be enforced.

    However a base level resolution for this is to create a duplicate description field and make one a calculated field to copy the value of the other. You would then set dependencies so that the initial fields hides when the calculated one is populated with something, and use the same principal on the calculated field. This will make it look as if the field is suddenly becoming read-only, where in fact it is simply swapping the fields over.

    If you are looking for something more than this let me know.

Children
  • Hi Liam,

    Im using Sugar Enterprise 7.6. Can help me get through this? :-)

    Thanks,

    Longki

  • i solved it using this http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/Extension_Framework/Dependencies/

    i created a file /custom/Extension/modules/Cases/Ext/Dependencies/description_readonly.php

    <?php

    $dependencies['Cases']['description_readonly'] =    array(

        'hooks' => array("edit"),

        'trigger' => 'not(equal($description,""))', //check if  the field has a value so that it will trigger

        'triggerFields' => array('description'),

        'onload' => true,

        //Actions is a list of actions to fire when the trigger is true

        'actions' => array(

            array(

                'name' => 'ReadOnly',

                //The parameters passed in will depend on the action type set in cases.description field

                'params' => array(

                    'target' => 'description',

                    'value' => 'true',

                ),

            ),

        ),

    );

    then created a blank file /custom/modules/Cases/Ext/Dependencies/deps.ext.php

    so that after Quick Repair and Rebuild the description_readonly.php will be merged there.

    after QRR you will find in that file the auto-generated merging of codes..

    <?php

    // WARNING: The contents of this file are auto-generated.

    //Merged from custom/Extension/modules/Cases/Ext/Dependencies/description_readonly.php

    $dependencies['Cases']['description_readonly'] =    array(

        'hooks' => array("edit"),

        'trigger' => 'not(equal($description,""))', //check if  the field has a value so that it will trigger

        'triggerFields' => array('description'),

        'onload' => true,

        //Actions is a list of actions to fire when the trigger is true

        'actions' => array(

            array(

                'name' => 'ReadOnly',

                //The parameters passed in will depend on the action type set in cases.description field

                'params' => array(

                    'target' => 'description',

                    'value' => 'true',

                ),

            ),

        ),

    );

    HTH,

    Longki

  • Found the very correct solution emailed by Ajay Kumar to me :-) as for the latter after you hover out to the field it will be automatically set to readonly even if you havent saved it yet. Here's the fix.

    QOUTE from Ajay:

    Hi Longki,

    Good day too!

    1.You can make certain fields readonly by writing dependency.

    2.If you want to make it fields to be readonly only specific views, you can try below.

    Extend "buildGridsFromPanelsMetadata" this method to custom,and push your fields into this.noEditFields variable,this is how sugar is making fields readonly.

    Below is the code snippet,you can copy this code and make changes according to your condition.I tried in recordview.

    Note:we no need to call this method on initialize.

    _buildGridsFromPanelsMetadata:function(panels){

            var noEditFields = new Array();
            this._super('_buildGridsFromPanelsMetadata',[panels]);
            noEditFields.push('phone_alternate');
            this.noEditFields=noEditFields;
        },

    Thanks & Regards

    AjayKumar B

    HTH,

    Longki Dela Cruz

  • Hi Longki,

    You have to make few changes in your dependency code to make it work when it is saved.You have given triggerFields as description,so dependency will get triggered,when we filled value for that.

    But,If you want to make it readonly once it is saved,you have to remove description field from triggerFields.Then it will work properly.

    Here is the modified dependency code.check it out.

    <?php
    $dependencies['Cases']['description_readonly'] =    array(
        'hooks' => array("edit"),
        'trigger' => 'true', //check if  the field has a value so that it will trigger
        'triggerFields' => array( ),
        'onload' => true,
        //Actions is a list of actions to fire when the trigger is true
        'actions' => array(
            array(
                'name' => 'ReadOnly',
                //The parameters passed in will depend on the action type set in cases.description field
                'params' => array(
                    'target' => 'description',
                    'value'=> 'not(equal($description,""))',
                ),
            ),
        ),
    );