cancel
Showing results for 
Search instead for 
Did you mean: 

Error when setting Top N options a second time (via the API)

Former Member
0 Kudos

I'm trying to set the Top N options for a group using the CR .NET API. The group already has a Top N sort defined for it in the report file.

My C# code looks like this:

        public void SetTopNOptions(bool top, int nGroups, bool discardOthers)

        {

            ISCRSort groupSort = reportDocument.ReportClientDocument.DataDefController.DataDefinition.Sorts[groupIndex];

            TopNSort topNSort = new TopNSort();

            topNSort.Direction = top ? CrSortDirectionEnum.crSortDirectionTopNOrder : CrSortDirectionEnum.crSortDirectionBottomNOrder;

            topNSort.DiscardOthers = discardOthers;

            topNSort.NIndividualGroups = nGroups;

            topNSort.SortField = groupSort.SortField;

            reportDocument.ReportClientDocument.DataDefController.SortController.Modify(groupSort, topNSort);

          }

This succeeds the first time, and I can show the report in a preview control & it displays the correct number of groups.

However, the second time I call this on the same ReportDocument I get a NullReferenceException when I call Modify. I think this is due to the fact that groupSort.SortField is null (and therefore so is topNSort.SortField).

Interestingly, if I try to do this using the Engine classes, I get the same behaviour!

            SortField sortField = reportDocument.DataDefinition.SortFields[groupIndex];

            TopBottomNSortField tbnsf = sortField as TopBottomNSortField;

            if (tbnsf != null)

                tbnsf.NumberOfTopOrBottomNGroups = nGroups;

The first time through this code succeeds, but the second time throws a NullReferenceError. I wouldn't be surprised if the Engine-level code is doing something pretty similar to the RAS code above.

Anyway, please repro and file a bug report.

Thanks

- rick cameron

Softrak

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Rick,

Try using the .Clone method to make the change from the original sort. That should copy all of the objects and allow you to make the change and then .Modify should work the second time.

Too busy right now to test it...

Log a case in SMP if the above does not work, it has a lot more weight when getting things fixed with a real company attached to it.

Don

Former Member
0 Kudos

Hi, Don

Thanks for the suggestion. I did try using .Clone and got the same behaviour.

I haven't logged a case in SMP before. Can you tell me how to do this?

Thanks

- rick cameron

Softrak

0 Kudos

Hi Rick,

You do have a support contract correct? I believe Softrak is an OEM Partner.... Check with your team, someone their should be able to add you and then show you how to create a case....

Don

Answers (0)