
There are times when you might not want a user to be able to edit content on a page. While Creatio does allow you to easily modify access permissions on the fly from a process, that might not provide the flexibility you need to do it conditionally, without modifying the record access permissions. You can also make individual fields read-only using business rules, but doing that for every field is unreasonable, and it also won’t work for details. However, this is a very easy task in Creatio to completely lock a record (or just parts of a record) from code on a page. In the scenario for this article, we’ll completely lock a contact record if it’s type is Employee, including all fields on the screen as well as all details. If the contact type is not employee, it will be editable as normal.
The “locking” or disabling of a page in Creatio is really controlled by an attribute you add on the page named “IsModelItemsEnabled”. However, there’s a few more items we need to add to our page for this to work. Let’s get the attribute added, add the following attribute to your page:
attributes: { "IsModelItemsEnabled": { dataValueType: Terrasoft.DataValueType.BOOLEAN, value: true } }
When we’re all done adding the needed items to the page, we’ll control whether the page is locked by simply setting that attribute to true or false using this.set("IsModelItemsEnabled", true), etc.
The next part we’ll need to add is something to the diff on our page. Copy the following and add it anywhere in the page diff:
diff: /**SCHEMA_DIFF*/[ { "operation": "merge", "name": "CardContentWrapper", "values": { "generator": "DisableControlsGenerator.generatePartial" } } //... ]/**SCHEMA_DIFF*/
This part will do all the actual work when we set our IsModelItemsEnabled attribute to true or false. The CardContentWrapper that we’re merging this into is the container for the edit page. We’re merging a generator into this container that will lock/unlock when we change the attribute. For our scenario, let’s wire up some code to change the attribute when the contact’s Type value changes. When the value is “Employee” we’ll lock the page.
attributes: { // the attribute we added earlier "IsModelItemsEnabled": { dataValueType: Terrasoft.DataValueType.BOOLEAN, value: true }, // the attribute to wire the change of our type field to our method "TypeChange": { dependencies: [{ columns: ["Type"], methodName: "onTypeChange" }] } }, methods: { onEntityInitialized: function() { this.callParent(arguments); // when record loads, check the type this.onTypeChange(); }, onTypeChange: function() { // type value was changed, check value and lock/unlock page var type = this.get("Type"); if (Ext.isEmpty(type) || type.displayValue != "Employee") { this.set("IsModelItemsEnabled", true); } else { this.set("IsModelItemsEnabled", false); } } }, // diff section we added earlier diff: /**SCHEMA_DIFF*/[ { "operation": "merge", "name": "CardContentWrapper", "values": { "generator": "DisableControlsGenerator.generatePartial" } } //... ]/**SCHEMA_DIFF*/
Now, when the record’s type is Employee the record will be locked. Not just the fields, but any details as well. However, what if there’s fields we want to exclude from this and leave editable? For example, maybe we want to allow for the type to be changed in any case? We can add a method named “getDisableExclusionsColumnTags” that returns an array of column names we want excluded from being locked. If we want to leave the Type field unlocked in any case, we can add the following:
getDisableExclusionsColumnTags: function() { return ["Type"]; }
We can do the same with details we want to leave unlocked as well using a function named “getDisableExclusionsDetailSchemaNames” that returns an array of detail names we want to be left as editable (meaning you can still add/edit/delete from the details normally). For an example, if we want to leave the Activity detail as unlocked and not changed when we set the attribute, we can add the following:
getDisableExclusionsDetailSchemaNames: function() { return ["ActivityDetailV2"]; }
Now we can still change the type field an also add/edit/delete activities as normal as well and the rest of the page will be locked. As a side note, if doing this on the contact page, the communication options detail doesn’t really respond well to this and doesn’t disable. However, for doing this anywhere else, it works well and usually without issue.
Hi Ryan,
Some fields on which “make field editable” business rule is applied are not getting locked.Is there any alternative of business rule?
Hi Ryan,
Looks like a useful feature; however, I cannot seem to get it to work as described. All elements on the page remain editable.