Sorting in a group report on Customer Name.

In classic NAV 2009 R2, we customized a report which shows group outstanding of 2 companies,data shown is correct

but customer needs that the data shown in report should be in ascending order of Customers Name.

I tried setting ascending order in customer dataitem property,

tried via code i.e. setcurrentkey to name and then ascending=true,but no luck.

Below is a screen shot of the dataitems being used.

Do you have the key created on the table?

g.

sorry , I meant the index :slight_smile:

Hi, I’m not able to see the screenshot, anyway is Customer the only dataitem you have?

8372.Capture.PNG

In this way customers will be sorted by name within the company they belong: if you need a general sorting it’s necessary to have the Customer as first dataitem.

You need to set the sorting on the customer dataitem. And again, ensure ,you have an index created on the table customer field name.

g.

Hi Manish,

You’ve gotten several answers to your question and, while they might initially seem to be saying different things, they’re actually all correct parts of a larger picture that forms the whole answer.

The first part of the answer that Faludigabor and Daniele both alluded to addresses the requirement for a key to be defined on the field that you’d like to sort by. If your sorted list can be indifferent to capitalization, then you can use the existing key “Search Name”. If none of the existing key definitions meet your requirements, you can define a new key that does. Then you would typically set that value in the DataItemTableView property of the data item. So, that’s the sorting bit.

Then, Daniele gave you another key piece of the puzzle by instructing you to make the Customer be the first data item and not Company. As he rightly noted, if you make the Company the first data item, you’ll get an alphabetized list of all of the customers in company A, then another list for company B, and that isn’t what you want. I’m presuming that you want a single list, alphabetized, that includes all of the customers fro all companies in the database?

And this is where the last piece of the puzzle comes in. Unless you have modified the property in the t_18 Customer table called DataPerCompany to NO from the default value YES, then you won’t be able to aggregate all of the records from all of the companies using the typical report data item hierarchy. Before you can export the complete list, you’ll first have to aggregate all of the customer records from all of the companies into a single temporary table, then sort that table, then use your report tools to display the data from the aggregated temporary table.

You’ll be using a function called CHANGECOMPANY on the Customer record so that you can tell NAV which set of Customer records you want to work with. Once you select which Customer set to work with, you’ll loop through that table, copying each record into a temporary record, You’ll repeat this process for each company, then you’ll export the report elements based on the temporary record. If you’re lucky, you can use a temporary copy of the Customer table (the only thing stopping you from doing that would be the possibility of duplicate customer numbers), and if you’re not lucky, you’ll have to build a generic buffer record to store all of the copied customers.

So, you can leave your data item definitions as they are, with company on top, then customer under company. In the OnPreDataItem trigger of the Customer record, you’ll add the command Customer.CHANGECOMPANY(Company.Name); If you wan the CustLedgEntry detail to go along with the report, you may need to build accommodations for that data as well. You probably won’t be able to get away with populating a common temporary copy of the record since the PK is an integer and will very likely duplicate across data sets. To handle this, you could probably define your own buffer table again, a working copy of the original table, with a slightly modified PK to allow for the duplicate source values.

Of course, if you HAVE already changed the DataPerCompany property on the Customer record to No, then just delete the Company data item from your report and change the sort order as we discussed earlier.

Hope that helps.