Announcement

Collapse
No announcement yet.

Conditionally disable the ability to create/edit entities

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conditionally disable the ability to create/edit entities

    I have entity A with field "Status". This entity has relation to entity B.
    Is it possible to disable create and edit B entities related to entity A when A.Status is different from "Active"?

  • #2
    Hi kacper,

    You can use the API before-save script which will throws a Conflict exception: https://docs.espocrm.com/administrat...ethrowconflict.

    To do this, go to Administration > Entity Manager > your entity B name > Formula > API Before Save Script and paste the following formula script:
    Code:
    // IMPORTANT: change entityA part to your entity A name in all the coincidences
    
    $entityAStatus = record\attribute('EntityA-name', entityAId, 'status'); 
    
    if (entity\isNew() && $entityAStatus != 'Active') {
        recordService\throwConflict("You can't create new entity B record when entity A status is different from Active.")
    }
    
    if (entity\isNew() == false && $entityAStatus != 'Active') {
        recordService\throwConflict("You can't edit this record when entity A status is different from Active.")
    }

    Comment


    • #3
      Hi, thanks for the answer. I wrote custom validation in PHP code for that, but I also want to disable ability to create and edit EntityB from the list in EntityA. As below. Is it possible with native Espo functions or should I modify this manually?

      Click image for larger version

Name:	image.png
Views:	141
Size:	20.4 KB
ID:	99567

      Comment


      • #4
        You can establish a sub-team with distinct roles (can't add entity B). If the status is active, the record should be assigned to the sub-team; otherwise, it should go to the main team.

        Comment


        • #5
          kacper,

          Based on your last screenshot and detailed explanation of the functionality you want, you can to do the following:

          1. In Administration > Entity Manager > Entity A > Layouts > Bottom Panels > Enabled click on the pencil that involves editing​:

          Click image for larger version  Name:	image.png Views:	0 Size:	37.6 KB ID:	102364​2. And > Field.

          Click image for larger version  Name:	image.png Views:	0 Size:	6.2 KB ID:	102365

          3. In the list of fields, select Status. After that, set the Status field equals to the Active option.

          Click image for larger version  Name:	image.png Views:	0 Size:	7.3 KB ID:	102366

          After saving the settings in Entity A, the Bottom Panels for Entity B will be displayed only when the record Status in Entity A is Active.

          Click image for larger version

Name:	image.png
Views:	65
Size:	11.7 KB
ID:	102369

          If the record status in Entity A is Inactive, then the panel for Entity B will not be displayed.

          ​​Click image for larger version

Name:	image.png
Views:	66
Size:	9.6 KB
ID:	102370
          Last edited by victor; 02-04-2024, 12:10 PM.

          Comment

          Working...
          X