how to disable edit option for records based on satus closed

I want to disable edit button and inline edit for records based on status value. how to do that??

Ex: i dont want give an edit option for status closed records. I have tried with this code but it is disabled Edit button only.

how to restrict from inline edit also.

Need help as soon as possible....

  1. <?php  
  2.     $dependencies['<module>']['<unique name>'] = array(  
  3.         'hooks' => array("edit"),  
  4.         //Optional, the trigger for the dependency. Defaults to 'true'.  
  5.         'trigger' => 'true',   
  6.         'triggerFields' => array('status'), //dropdown field name   
  7.         'onload' => true,  
  8.         //Actions is a list of actions to fire when the trigger is true  
  9.         'actions' => array(  
  10.             array(  
  11.                 'name' => 'ReadOnly',  
  12.                 //The parameters passed in will depend on the action type set in 'name'  
  13.                 'params' => array(  
  14.                     'target' => 'edit_button'//edit button name  
  15.                     //id of the label to add the required symbol to  
  16.                     'label' => 'LBL_EDIT_BUTTON_LABEL',  
  17.                     //Set required if the status is closed  
  18.                     'value' => 'equal($status, "Closed")' // base on selected value button will be ReadOnly  
  19.                 )  
  20.             ),  
  21.         ),  
  22.         //Actions fire if the trigger is false. Optional.  
  23.         'notActions' => array(),  
  24.     );  
  • Hi Ash,

    If you need to lock a record based on certain record's specific condition, you should look into custom ACLs.

    Have a look at this blog post for a couple of examples and more details https://enricosimonetti.com/powerful-customisations-with-sugars-acl/ 

    All the best

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Hi ,

    Thanks for your article, it works well, but I have a specific case and I didn't manage to perform what I want.

    Is it possible to add several conditions in the $bean_lock_mappings property ? 

    In my case, I want to disable the edit button when the status of a quote is "Closed Lost" or "Closed Dead" or "Closed Accepted" : 

    // has to match on all conditions
    protected $bean_lock_mappings = array(
        'Quotes' => array('status' => 'Closed Losed'),
    );

    How can I do that ? Should I create 3 different SugarAclLock file for each status ? 

    Thanks a lot for your feedback.

    Best regards,

    Enes

  • Of course you can match on any condition you would like, but you would have to code the specific logic accordingly, that provided code is no longer "plug and play".

    The point is that if you return false from "_canUserWrite" the record won't be editable, if you return true, it will be editable. This is unless other roles/acls prevent it from being editable in the first place. The most restrictive permission will win

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Hello Enrico,

    I finally managed to make what I want.

    I added an array on the condition as you can see below : 

    // has to match on all conditions
    protected $bean_lock_mappings = array(
        // 'Quotes' => array('quote_stage' => 'Closed Lost'),
        'Quotes' => array('quote_stage' => array('Closed Lost', 'Closed Dead', 'Closed Accepted')),
    );

    and in the condition, I modified in order to check against the array or a single value :

    if(empty($bean->$field) || (is_array($value) && !in_array($bean->$field, $value)) || (!is_array($value) && $bean->$field != $value)) {
        // all conditions have to match, if any field is different from the condition or empty, allow
        return true;
    }

    And it works !

    Have a nice day, and best wishes for this new year !

    Best regards,

    Enes