Getting a group sort type (CrSortDirectionEnum)

I needed to get the sort directon for a GROUP sort. However, using the following code is invalid for groups (at least if the group is not asc/desc):
CrystalDecisions.CrystalReports.Engine.SortFields crystalSortFields = report.DataDefinition.SortFields;
if (crystalSortFields != null)
    foreach (CrystalDecisions.CrystalReports.Engine.SortField crystalSortField in crystalSortFields)
        switch (crystalSortField.SortDirection)
            case CrystalDecisions.Shared.SortDirection.AscendingOrder:
                break;
            case CrystalDecisions.Shared.SortDirection.DescendingOrder:
                break;
            case CrystalDecisions.Shared.SortDirection.TopNOrder:
            case CrystalDecisions.Shared.SortDirection.BottomNOrder:
            default:
                break;
After some searching, and some trial and error, I found a solution:
using System.Reflection;
using System.Runtime.InteropServices;
using CrystalDecisions.ReportAppServer.DataDefModel;
CrystalDecisions.CrystalReports.Engine.SortFields crystalSortFields = report.DataDefinition.SortFields;
if (crystalSortFields != null)
    foreach (CrystalDecisions.CrystalReports.Engine.SortField crystalSortField in crystalSortFields)
        if (crystalSortField.SortType == CrystalDecisions.Shared.SortFieldType.GroupSortField)
            MethodInfo getRasSort = crystalSortField.GetType().GetMethod("get_RasSort", BindingFlags.NonPublic | BindingFlags.Instance);
            object rasSort = getRasSort.Invoke(crystalSortField, System.Type.EmptyTypes);
            IntPtr iunkwn = Marshal.GetIUnknownForObject(rasSort);
            switch ((CrSortDirectionEnum)((dynamic)rasSort).Direction)
                case CrSortDirectionEnum.crSortDirectionAscendingOrder:
                    break;
                case CrSortDirectionEnum.crSortDirectionDescendingOrder:
                    break;
                case CrSortDirectionEnum.crSortDirectionBottomNOrder:
                case CrSortDirectionEnum.crSortDirectionBottomNPercentage:
                case CrSortDirectionEnum.crSortDirectionNoSortOrder:
                case CrSortDirectionEnum.crSortDirectionTopNOrder:
                case CrSortDirectionEnum.crSortDirectionTopNPercentage:
                default:
                    break;
BTW, this is VS2010 w/ CR for VS2010.

Hello Pablo
Many, many thanks for sharing this solution. I'm going to make a KB out of this as it is a good piece of knowledge to capture.
Happy coding,
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

Similar Messages

  • How to get po item condition type according schema group

    hi experts,
    i want to get po item condition type according schema group.
    for example, in xk03, if the "schema group, vendor"in purchasing data view is set to 'Z3', in the purchase order which is made for this vendor, the po item's gross price condition type is hwxx.
    if the "schema group, vendor" is set to 'Z2', the po item's gross price condition type is pbxx.
    my question is : how to get po item condition type according schema group?
    hunger for ur advice and thanks a lot!

    several steps you need to go
    1. you need to get the purcahsing group schema against your purchasing group from table T024E.
    2. get the vendor group schema from vendor master data table LFxxxxxx
    3. get the pricing schema from table TMKS via the selection criteria purchasing group schema and vendor group schema
    4. go to the table T683S via inputing Usage, application and pricing determination procedure.
    5. now you got it.

  • Changing group sort programmaticaly

    Is there a way to change or create a "group sort" formula from vb.net 2005? I am using Crystal reports XI R2.
    I need to be able to sort by ItemID, Qty, Amount or Volume, create the sort formula and be able to change the sort direction also.
    I tried to use:
                Dim crSortField As SortField
                Dim fieldDef As DatabaseFieldDefinition
                For Each crSortField In cr.DataDefinition.SortFields
                    fieldDef = cr.Database.Tables(0).Fields(crSortField.Field.Name.ToString)
                    crSortField = cr.DataDefinition.SortFields(1)
                    crSortField.Field = fieldDef
                    crSortField.SortDirection = SortDirection.DescendingOrder
                Next
    I get an error that says: The sort is not defined in the data definition.
    Any help would be appreciated.

    Here is a sample I had kicking around.
    Keep in mind that you must have at least one sort already set up to be able to change it. Otherwise you'll need to use the RAS SDK to add sorts at runtime.
              private void Form1_Load(object sender, System.EventArgs e)
                   ConfigureCrystal();
              private void ConfigureCrystal()
                   // Instantiate and load the Sort Report.rpt
                   crReportDocument = new ReportDocument();
                   crReportDocument.Load(Application.StartupPath + "\\..\\..\\Sort Report.rpt");
                   // Change the sorting for the group to sort based on the summary
                   // of @Order Amount x Tax.
                   SortFields crSortFields = crReportDocument.DataDefinition.SortFields;
                   foreach(SortField crSortField in crSortFields)
                        if (crSortField.Field.Name == "Count ({Orders.Order ID}, {Customer.Customer ID})")
                             // Get the new field to sort on
                             FieldDefinition crFieldDefinition = crReportDocument.DataDefinition.SummaryFields[1];
                             crSortField.Field = crFieldDefinition;
                             crSortField.SortDirection = SortDirection.DescendingOrder;
                             break;     // break out of the foreach loop
                   // Change the sorting for the record type as well
                   foreach(SortField crSortField in crSortFields)
                        if(crSortField.Field.Name == "Order ID")
                             FieldDefinition crFieldDefinition = crReportDocument.Database.Tables[1].Fields[1]; // the Order Amount in in the 2nd table and 2nd field
                             crSortField.Field = crFieldDefinition;
                             crSortField.SortDirection = SortDirection.DescendingOrder;
                             break; // break out of this foreach loop
                   // Set the ReportSource of the CrystalReportViewer control
                   crystalReportViewer1.ReportSource = crReportDocument;
              private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
                   // clean up
                   crReportDocument.Close();
                   crReportDocument.Dispose();
                   crReportDocument = null;

  • How do I change the number in a Top N Group Sort

    I have a report that I have grouped on a particular field (Cust.Name specifically). I then used the group sort expert and selected the Top N selection in the combo box under the Cust.Name tab. I put in a default number of 20. What I want to do is to set this number for the Top N group sort via .NET. Does anyone know the correct method for doing this in either VB.NET or C#.NET. I am using VS 2005 Pro and the embedded Crystal Reports engine for VS.NET. Thank you.
    Ed Cohen

    Hello, Edgar;
    In the bundled version of Crystal Reports 10.2 in Visual Studio .NET 2005 you will need to use the following code:
    Private Sub Set_TopN()
            Dim TopNSortField As TopBottomNSortField
            'Get the Sort field by index
            'Cast it as a TopBottomNSortField
            If TypeOf crReportDocument.DataDefinition.SortFields.Item(0) Is TopBottomNSortField Then
                TopNSortField = crReportDocument.DataDefinition.SortFields.Item(0)
                TopNSortField.NumberOfTopOrBottomNGroups = 10
            Else
                TopNSortField = Nothing
            End If
        End Sub
    In a full version of Crystal Reports there is an option to create a parameter as a number such as {?TopN} and then pass the value to it at runtime.
    In the Crystal Reports designer you need to create the parameter and then go to Report|Group Sort Expert.
    Choose TopN based on your field.
    Where N is... You will need a number there. I used 1. But then I clicked on the Formula editor [X+2] and added the parameter field {?TopN}.
    Passing the parameter at runtime ran the number I requested.
    Elaine
    Edited by: Elaine Dove on Mar 3, 2009 12:12 PM

  • Sum of a sum when using Top N in the Group Sort Expert

    Hi All,
    I have a small problem I can't quite seem to work out.
    I have a report where each line is for a particular Product, and is a summation of the Sales for that Product over several Locations. When you click on the line, it shows the breakdown of Sales over each Location.
    I use the Group Sort Expert to display the Top N results, where the 'N" is set in a formula to a parameter passed in to the report, so the user can select the top 5,10,50 etc. Products across all Locations.
    At the bottom of the report, I want to have a sum of a column of Sales $. I need that sum to only be a sum of the Top N records selected.
    Since each line is a summation of the all the products for the Locations, what I need is a sum of that sum for the Top N, but Crystal will not let you add the sum of a sum, so I'm not sure how to accomplish this.
    If I just do a sum of the underlying values I get a total for all the Products, regardless of the Top N.
    Hope that makes some sense !
    Many Thanks
    Paul

    Hi Sastry,
    I tried your suggestion, thanks, but I don't think it's the answer. For a start Crystal will not let me do that, it pops up a message box when I try to run the report "A running total cannot refer to a print time formula. Details: Record Number". I also added the record number field next to the lines in the report to see what the result would be, and I don't think it would work anyway.
    Here is an example using Units sold:
    Product Name--LocationUnits Sold--Record Number
    Product A -<All Stores>----8
    Store A--1--
    1
    Store B--3--
    2
    Store C--4--
    3
    Product B--<All Stores>--3      
    Store A--2--
    4
    Store B--1--
    5
    Product C--<All Stores>--
    1
    Store A--1--
    6
    Note that only the bold lines are shown in the report,. If you click on the bold line, then the breakdown of the stores is shown. For the above example, I am showing the Top 2 units across all stores (so Product C is not shown at all), but there are actually 5 records, so if I used a formula where RecordNumber <=N, where in this case N=2, I would get a total units sold of 1 + 3 (records 1 and 2) which is incorrect.
    I will have more of a think on this and see if I can find a solution, in the mean time, any other suggestions ? Is there some wya of checking if the line is visible maybe ?
    Thanks for your time !
    Paul

  • How to get the groups a computer is member of in AD with Quest Powershell?

    Hi all
    I would need a script in Quest PowerShell that gathers the groups that multiple computers are member of in Active Directory. I have this script, but what it does is to get USERNAMES from a .txt file and then display the groups
    each user is member of in AD. I couldn't modified it so instead of USERNAMES in the txt file I can put computers name, here's the code:
    $out = @()
    Get-Content M:\Tools\Reportes_Power_Shell\Contenedor_Power_Shell\Users.txt | ForEach {
    $date = (Get-Date).ToString()
    $username = $_
    $displayName = (Get-QADUser $username -Properties DisplayName).DisplayName
    $groups = Get-QADMemberOf $username | Sort-Object Name
    ForEach ( $group in $groups ) {
    $obj = New-Object -TypeName PSObject
    $obj | Add-Member -MemberType NoteProperty -Name Date -Value $date
    $obj | Add-Member -MemberType NoteProperty -Name UserName -Value $username
    $obj | Add-Member -MemberType NoteProperty -Name DisplayName -Value $displayName
    $obj | Add-Member -MemberType NoteProperty -Name GroupName -Value $group.name
    $out += $obj
    $out | Export-CSV M:\Tools\Reportes_Power_Shell\Reportes_de_Power_Shell_y_AD_Info\Users_Memberships.csv
    Thanks!

    I did it but didn't work out, I get this error:
    Get-QADMemberOf : Ambiguous identity: <NAME OF THE COMPUTER>.
    At line:5 char:30
    +     $groups = Get-QADMemberOf <<<<  $username | Sort-Object Name
        + CategoryInfo          : NotSpecified: (:) [Get-QADMemberOf], IdentityException
        + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.BusinessLogic.IdentityException,Quest.ActiveRoles.
       ArsPowerShellSnapIn.Powershell.Cmdlets.GetMemberOfCmdlet
    I can't help with Quest, but here's an example using the AD module:
    Get-Content .\computerList.txt | ForEach {
    $computerName = $_
    $props = @{
    ComputerName = $computerName
    Groups = ''
    try {
    $details = Get-ADComputer $computerName -Properties memberOf -ErrorAction Stop
    $props.Groups = (($details.memberOf | ForEach { (Get-ADGroup $_).Name }) | Sort) -join ','
    } catch {
    $props.Groups = 'ERROR'
    New-Object PsObject -Property $props
    } | Select ComputerName,Groups | Export-Csv .\GroupList.csv -NoTypeInformation
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • MATERIAL GROUP & MOVEMENT TYPE

    Hi,
    I want a report in which Material Group & Movemt type combinely should be display.
    Allready search in SDN
    Thanks in Advance
    Regards
    Vinay

    Hi vinay,
    Take the help of abaper to get the report for material group and the movement type.
    Quick viewer reporting tool will be used for this report SQVI
    This link will be useful in understanding the SQVI
    http://www.sapdb.info/sqvi-quick-viewe/
    Regards,
    Nani

  • Use parameter to specify "N" in Top N Group Sort

    I've successfuly set up a parameter which is passed to the Group N Sort criteria.
    Is there a way I can use this to set NO group sort? I've tried setting it to zero & 999999999 but it falls over.

    I think you can enter the values only between 1 to 32767. You can try creating a sample report with groups in it and go to group sort expert and select top N and try to add the value 0 then you will get a popup saying "Please enter an integer between 1 and 32767"
    Regards,
    Raghavendra

  • GROUP SORT PARAMETER

    I have a report with a group sort of the "Top N" items based on profit.  I already have a parameter that allows the user to specify the "N", but I want to also give the option to change the group sort based on sales or units sold.  Is there a way to do that?

    hello all,
    actually Brian's solution is correct...i use this method all the time.
    add two more steps to his solution...you should have created a formula with syntax
    Select {?GroupField}
       Case "Sales" :{table.SALES}
       Case "Units Sold" :{table.UNITS_SOLD}
       Default :{table.SALES};
    1) now add this formula to the details section, right click on it, and add a Summary, type = Sum.
    2) now go to the Group Sort Expert and add the formula, removing any other sorts in there already.
    you can now sort the groups on this formula that he gave you.
    if you have crystal reports 2008 or 2011 you can also use Interactive Sorts instead of using a parameter / prompt.
    cheers,
    jamie

  • Group Sort Expert Top N

    In Group Sort Expert I have a group called @Sku and I want to select the top 500 based on Sum of @SortByData which works except the totals are for the whole group and not just the top 500.
    Also I would like to select Ascending/Descending based on a parameter field IN the Group Sort Expert since I'm using a based on field (not in Group Expert Change Group Options).

    Hi sharonamtowler,
    My requiremnet is TOP N Materials based on the Current Availiable Stock in each Plant.  In CR from my db, I get four records in Details section for each Material (on 4 weeks, let say 48,49,50,51 ) of a Plant.
    I have grouped on Plant & material. 
    But to get Top N Materials I have to do Summation(Current Availiable Stk) which mean in My Material Group Section I get the Sum of Current availibale Stock of 4 weeks. But I need Top N based on the last weeks Current Availible Stock.
    How to do this?
    I left Plant in Group Sort Expert with No Sort and on Material I have given TOP N.
    I need to know whether only Summation Values should be used in Group sort expert ?
    please some help me solvethe issue.
    Edited by: KRISHNA CHAITANYA B on Dec 29, 2009 6:12 AM

  • Group sort

    Hi
    I have a date field and i did a group sort on that feild, for some reason its not giving me the months in order.For example
    the result must be like below
    JAN 08
    FEB 08
    MARCH 08
    APR 08
    Instead its showing
    MARCH08
    JAN08
    APRIL 08
    FEB 08
    please any advice will be of great help.
    Thanks

    You can display the data any way you want, but if you sort on a date that is in a "Month, Year" format, they will sort alphabetically. You need to sort on the numeric month to get things to display in standard calendar order.
    Show the date as you want, but sort on a calculation that uses the numeric month (and do not sort on the date being displayed). When setting up the sort, check the "Hidden" box, and the column will not be displayed.

  • Getting a non sorted list of members

    I am trying to copy data from one set of products to another for 2 entities. Entity1 uses Map1 products whilst Entity 2 uses Map2 My sample Product dimension structure is as follows:-
    Product
    |_ProdA
    |_ProdB
    |_ProdC
    |_ProdE
    |_ProdF
    |_Map1
    |_ProdA (shared)
    |_ProdB (Shared)
    |_ProdC (Shared)
    |_Map2
    |_ProdA (shared)
    |_ProdF (shared)
    |_ProdE (shared)
    The mapping is defined by the position of the shared products in Map1 and Map2 eg Prod A maps to ProdA, Prod B maps to Prod F etc
    I have used the MDSHIFT function but I cannot get an unsorted member list (@RELATIVE etc sorts the retrieved member list and also removes duplicates).
    Is there another way to copy data from Map1 to Map2?
    Thanks

    i'm trying to generate a sorted list of integers but
    there is a restriction that these sorted randomed
    generated integers must be uniformaly distribued
    within the range of numbers needed for example (1
    -1000)??does any body know how can we generate random
    numbers and at the same time sorted with uniform
    distribution??
    i have thought about an idea like starting from 1 for
    example and and then let the difference between each
    two numbers is random within 1 to 10 then adding this
    random integer to the last number generated and soo
    on .. but i don't feel it is efficient as maybe the
    random difference would be 1 each time . so i will
    never get a uniformly sorted list .. any ideas or
    suggestions ,please??My guess is that you generate the numbers first, then sort them. If you use the pseudorandom number generator, Random, will generate numbers with a roughly uniform distribution. You have to do some work to it if you want some other type of distribution.

  • Import Group Sort Order

    In list view, if I select the "Import Group" column, that should sort the contents in the order they were imported, correct? It does not. It does group import groups together, but whole groups are out of sequence.
    Am I doing something wrong?
    Also, how can I get "Import Group" to show up in the pull down menu next to the list view or image view icons of the browser? The "custom" option at the bottom is always grayed out.
    Aperture 1.5   Mac OS X (10.4.9)  

    I do my sorting within an Album. I then drag the Album (not the photos) into my movie and the sequence stays intact.

  • Group filter type

    Hi all
    I have populated Group Filter Type  in GROUP dimension then assigned at Business rules for specific group( in GROUP Dimension) to eliminate or reverse the accounts in different way from other groups. Maintained separate DSRC, Account properties etc.
    I wont get any result on spefific group that has GROUP FILTER TYPE and its BPC NW 7.5   the systemw where test in process.
    appreciated your help/guidence
    Thanks
    Ramana

    thanks

  • How to get SharePoint Groups using Javascript in SP2013 ?

    How to get SharePoint Groups using Javascript in SP2013 , not JSOM please

    Here is the code that worked for me:
    <script type="text/javascript">
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups";
      var requestHeaders = { "accept" : "application/json;odata=verbose" };
      $.ajax({
        url : requestUri,
        contentType : "application/json;odata=verbose",
        headers : requestHeaders,
        success : onSuccess,
        error : onError
      function onSuccess(data, request){
    var s='';
     for (var i = 0; i < data.d.results.length; i++)
    s +=data.d.results[i].LoginName+'\n';
        alert(s);
     function onError(error) {
        alert("error");
    </script>

Maybe you are looking for

  • Difference between in and exist?

    difference between in and exist?

  • Is there a way to automatically shut down laptop when power button pressed?

    Of all the things I am having to struggle through a learning curve on MacOS (converted from Windows), this might seem like a rather benign concern, but I'm going to ask anyway. . . I would like for my laptop to automatically go through a shutdown pro

  • 2 dvrs or single multi room dvr???

    i currently have one DVR set up for multi room $19.99 and one standardt STB $4.99.    My wife tapes tons of standard programs and watches them all in the bedroom on the STB (non HD TV there).   This of course limits what i can watch on the good HD DV

  • Retaining the fileName inside the zipped files

    Hi Experts, I am working on a file to file scenario, in which the files have to be picked up the files in pair(pdf) and zip them  and post in the particular folder. I have used PayloadZipBean for zipping the files, but not able to get the original fi

  • Older version files, can't open

    I created interactive vidoes with Micromedia Director, 2007. The new Adobe director no longer recognizes/accepts these files. When looking for older versions to download, my Mac's most recent operating system will no longer support the files either.