Disallow deletion of record based on value.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rinorway
    Senior Member
    • Feb 2016
    • 179

    Disallow deletion of record based on value.

    Reading the example of https://docs.espocrm.com/development/dynamic-handler/ does anyone know how to disable deletion of a record based on a field value ?

    Even if you cannot protect a record from deletion, at least the UI would not allow it.

    Eg: "Deletion of the person with name "Queen" is not allowed".

    Any other suggested mechanism would be welcome.
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    #2
    Using the example in the documentation you could write something like this in the script
    client/custom/src/account-dynamic-handler.js
    Code:
        controlFields: function () {
            if (this.model.get('name') === "Queen") {
                this.recordView.removeButton('delete');
            }
         },
    You can see a more elaborate example of using dynamic handler in this post. https://forum.espocrm.com/forum/deve...gic-conditions

    The above will hide the delete button in detail view.

    I don't think that it's possible to remove the "remove" row option in list view for a specific row, but if you want to remove the "remove" option in list view (row options) for all records you can follow these steps:

    1) Create custom view: client/custom/src/views/record/list.js
    Code:
    define('custom:views/record/list', 'views/record/list', function (Dep) {
    
        return Dep.extend({
    
            rowActionsView: 'views/record/row-actions/view-and-edit',
    
        }
    
    }
    2) Edit your entity's clientDefs to let Espo know that a custom view needs to be used when rendering a list of records for this entity:
    Code:
    {
        "recordViews": {
            "list" : "custom:views/record/list"
        }
    
    }
    Last edited by telecastg; 01-26-2021, 05:22 PM.

    Comment

    Working...