Article

crt.NextSteps -> linked through the wrong column

Hi everybody,

As many of you know, Freedom UX includes a nice “Next Steps” component, which is implemented on a page like this:

{
	"operation": "insert",
	"name": "NextSteps_5ogvjc1",
	"values": {
		"type": "crt.NextSteps",
		"masterSchemaId": "$Id",
		"cardState": "$CardState",
		"layoutConfig": {
			"colSpan": 2,
			"column": 1,
			"row": 1,
			"rowSpan": 1
		},
		"masterSchemaName": "Contact",
		"bindingColumns": []
	},
	"parentName": "GridContainer_vlwf54t",
	"propertyName": "items",
	"index": 0
}

Everything works fine until your Activity schema contains multiple columns referencing the same entity (for example, several lookups to Contact). In such cases, you may notice that activities displayed in the Next Steps component are linked incorrectly.

Example: You have the OOTB Contact column and a custom column SomeOtherContact. On the Contact form, you expect Next Steps to show only activities linked via the Contact column. However, after implementing the component, it turns out that activities are linked via SomeOtherContact instead.

As nothing in the component is customizable, here is an explanation of the problem and a possible workaround.

Why does this happen?

The Next Steps component is processed by the GetNextSteps method inside the ActivityNextStepQueryExecutor class. This method internally calls GetRelatedColumn, which is responsible for determining which Activity column should be used to filter activities for the given entity.

The issue is that GetRelatedColumn returns the first matching column from the EntityConnection table, based solely on the relation type — not on the column name, not on configuration, and not on the Position field.

The ESQ used inside GetRelatedColumn has no ORDER BY clause, even though the EntityConnection table contains a Position column that could be used for sorting. Because of this, the database returns rows in the default order, which is determined by the primary key — Id.

As a result:

  • the “first” matching connection is whichever row happens to have the lowest Id
  • if your custom column has a lower Id, it will be selected instead of the OOTB column
  • Next Steps will then filter activities using the wrong column

Workaround:   If activities in Next Steps are linked through the wrong column, you can adjust the Id of the desired connection in the EntityConnection table so that it becomes the first one returned by the query. After that, Next Steps will use the correct column.

PS. property "bindingColumns": [] is not operational yet.

PPS. [For creatio developers] Can the value of the property bindingColumns be added into this method somehow like this?     

public List<NextStepModel> GetNextSteps(string entityName, Guid entityId, List<string>bindingColumns) {...}

then it will be possible to use those columns directly or when bindingColumns is empty, current approach still can be used as a default:

if (bindingColumns != null && bindingColumns.Count > 0) {
	var filterGroup = new EntitySchemaQueryFilterCollection(esq, LogicalOperationStrict.Or);
	foreach (var columnName in bindingColumns) {
		var inGroup = new EntitySchemaQueryFilterCollection(esq, LogicalOperationStrict.And) {
		esq.CreateFilterWithParameters(FilterComparisonType.IsNotNull, columnName),
		esq.CreateFilterWithParameters(FilterComparisonType.Equal, columnName, entityId)
		};
		filterGroup.Add(inGroup);
	}
	esq.Filters.Add(filterGroup);
} else {
	var relatedColumn = GetRelatedColumn(entityName);
	esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.IsNotNull, relatedColumn.Name));
	esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, relatedColumn.Name, entityId));
}

It will help much, believe me. 

Like 1

Like

Share

0 comments
Show all comments