Skip to Content
0
May 26 at 12:02 AM

Sorting by FormulaField

57 Views Last edit May 26 at 01:24 PM 2 rev

I've begun the task of bringing out CR to the 21st century. The templates were created more than 10 years ago, as well as the application written in Visual Basic that allows a user to pick different options before they click a button for generating a report.

So far the process hasn't been too bad but I've stumbled upon something that I can't figure out.

In VB, there's a line of code that sorts the report by a database table field:

Report.RecordSortFields.Add Report.Database.Tables(1).fields.GetItemByName("Name"), crAscendingOrder

I've successfully got that same logic working using the lines below

DatabaseFieldDefinition databaseFieldDefinition = Report.Database.Tables["Bureau"].Fields["Name"];

SortField sortField = Report.DataDefinition.SortFields[0];

sortField.Field = databaseFieldDefinition;

sortField.SortDirection = SortDirection.AscendingOrder;

The other type of sorting is what I'm struggling with.

The VB line of code is:
Report.RecordSortFields.Add Report.FormulaFields.GetItemByName("AssetName"), crAscendingOrder

As you can see, unlike the above example this is sorting by formula field. I can't seem to figure out how to write the code for this.

I know I can get the formula field using the below line but can't seem to make it work:

Report.DataDefinition.FormulaFields["AssetName"];

Any help would be appreciated