How to Programmatically Toggle the Enabled or Visible Property of a Field on a Page in Creatio

Making a field enabled or visible can be a very easy process and can be done in different ways. One way you can do it is with business rules but sometimes what you’re trying to do can be too complex for a business rule. For example if you need to disable or hide a field based on the results of an entity schema query tr some other complex conditions, you can’t do that with a business rule. Another way is you can enable/disable or show/hide fields programmatically. In this article I’ll walk you through the steps to do so.

The steps for enabling/disabling or showing/hiding fields programmatically are:

  1. Add a boolean attribute to the page
  2. Bind the attribute to the “enabled” or “visible” property of the field in the diff
  3. Set the attribute as true or false to enable or disable (or show or hide) the field on the page

When you add your boolean attribute to your page it will look something like this:

attributes: {
	"IsTypeEnabled": {
		dataValueType: Terrasoft.DataValueType.BOOLEAN,
		type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
		value: false

Note, the value you set in the attribute is what you want to have the default value be.

When binding your attribute to your field the code will look like this:

	"operation": "merge",
	"name": "AccountType",
	"values": {
		"layout": {
			"colSpan": 24,
			"rowSpan": 1,
			"column": 0,
			"row": 2
		"bindTo": "AccountType",
		"enabled": {
			"bindTo": "IsTypeEnabled"

Notice the enabled property is bound to our attribute.

Now to enable or disable the field you have to set the attribute to true or false in the same way you would set anything on the page using this.set.

if (SomeCondition) {
    this.set("IsTypeEnabled", true);
    this.set("IsTypeEnabled", false);

The point is you can’t directly change things that are in the diff. Instead you bind things in the diff to an attribute and then just change the attribute.

NOTE: you can do this technique with anything on the page (binding an attribute to an enabled or visible property in the diff), including field groups and details.

Want content like this delivered to your inbox? Sign up for our newsletter!

Submit a Comment

Your email address will not be published. Required fields are marked *