Invalid field number returned after changing grouping/sorting through SDK

    We have a Crystal Report version 2008 with 2 Group fields defined and 3 other Sort fields.  Our application uses the SDK to overwrite the grouping and sorting in the report.    The application will remove all sort and group fields (using ReportAppServer.Controllers.SortController.Remove) then add back in any sorts or groups that the user wants to use.

    The operations to remove and add the sort and group fields works correctly.  However, when CrystalReports.Engine.Table.ApplyLogOnInfo is called later, it fails with Invalid Field Number.  This does work if the first field added back in was one of the group fields; if a different field is added first, then I receive this error.

    This code worked correctly when running version 12 of the CrystalReports.Engine; it now fails since going to version 13.  I attempted to apply the most recent service pack and am still receiving the error, but when calling a different API.

    Are there any known issues with overriding the report grouping, particularly with version 13 of the runtime engine?

    Thank you for any insight.

    We have a Crystal Report version 2008 with 2 Group fields defined and 3 other Sort fields.  Our application uses the SDK to overwrite the grouping and sorting in the report.    The application will remove all sort and group fields (using ReportAppServer.Controllers.SortController.Remove) then add back in any sorts or groups that the user wants to use. The operations to remove and add the sort and group fields works correctly.  However, when CrystalReports.Engine.Table.ApplyLogOnInfo is called later, it fails with Invalid Field Number.  This does work if the first field added back in was one of the group fields; if a different…

    Invalid field number returned after changing grouping/sorting through SDK

    Very Helpfull

    User Rating: Be the first one !
    Add Comment
    1 Answer(s)

      Hi Stephanie,

       

      Sorry, after looking at my code it was not applying a second time it was saving the report, this triggers the update happen..

       

      Here’s my code:

       

      int GRsortIndex = 0;

      int FLDsortIndex = 0;

       

      IsRpt = false;

      //SortDirection sd = rpt.DataDefinition.SortFields[1].SortDirection;

      //rpt.DataDefinition.SortFields[1].SortDirection = SortDirection.NoSortOrder;

       

      SortController sortController = rptClientDoc.DataDefController.SortController;

      //sortController.Remove(GRsortIndex); // Sort of works for Groups – set the sort type to original order

      //try

      //{

      //    // you connot add a No sort, to remove the sort so you have no sort simply delete the sort and then save the report and reopen it. Only way to update the collection.

      //    //sortController.ModifySortDirection(GRsortIndex, CrSortDirectionEnum.crSortDirectionNoSortOrder);

      //}

      //catch

      //{

      //    //btnSQLStatement.Text = “ERROR: ” + ex.Message;

      //}

       

      foreach (CrystalDecisions.ReportAppServer.DataDefModel.Sort RASSortField in rptClientDoc.DataDefController.DataDefinition.Sorts)

      {

      foreach (SortField crSortField in rpt.DataDefinition.SortFields)

      {

      if (RASSortField.SortField.FormulaForm == crSortField.Field.FormulaName)

      {

      if (GRsortIndex >= 0)

      {

      if (crSortField.SortType.ToString() == CrystalDecisions.Shared.SortFieldType.GroupSortField.ToString())

      {

      textBox1 = “Group Sort:\n “;

       

      // don not remove this is to alter sorts only

      ////SortController sortController = rptClientDoc.DataDefController.SortController;

      ////sortController.Remove(GRsortIndex); // Sort of works for Groups – set the sort type to original order

      //try

      //{

      //    // you connot add a No sort, to remove the sort so you have no sort simply delete the sort and then save the report and reopen it. Only way to update the collection.

      //    sortController.Remove(GRsortIndex); // Sort of works for Groups – set the sort type to original order

      //    //sortController.ModifySortDirection(GRsortIndex, CrSortDirectionEnum.crSortDirectionNoSortOrder);

      //    rptClientDoc.VerifyDatabase();

      //}

      //catch (Exception ex)

      //{

      //    btnSQLStatement.Text = “ERROR: ” + ex.Message;

      //}

      //////RASSortField.SortField.Name = @”DistinctCount (Employee_Options.EMPLOYEE Full Name, Employee_Options.EMPLOYEE Hire Date, ‘Monthly’)”;

      // do not remove this is to alter sorts only

       

      IsRpt = false;

      GRsortIndex++;

      flcnt++;

      }

      else

      {

      textBox1 = “Record Sort:\n “;

      }

       

      …..

       

      Code is commented out….

       

      Don

      Add Comment

        Hi Stephanie,

         

        Sorry, after looking at my code it was not applying a second time it was saving the report, this triggers the update happen..

         

        Here’s my code:

         

        int GRsortIndex = 0;

        int FLDsortIndex = 0;

         

        IsRpt = false;

        //SortDirection sd = rpt.DataDefinition.SortFields[1].SortDirection;

        //rpt.DataDefinition.SortFields[1].SortDirection = SortDirection.NoSortOrder;

         

        SortController sortController = rptClientDoc.DataDefController.SortController;

        //sortController.Remove(GRsortIndex); // Sort of works for Groups – set the sort type to original order

        //try

        //{

        //    // you connot add a No sort, to remove the sort so you have no sort simply delete the sort and then save the report and reopen it. Only way to update the collection.

        //    //sortController.ModifySortDirection(GRsortIndex, CrSortDirectionEnum.crSortDirectionNoSortOrder);

        //}

        //catch

        //{

        //    //btnSQLStatement.Text = “ERROR: ” + ex.Message;

        //}

         

        foreach (CrystalDecisions.ReportAppServer.DataDefModel.Sort RASSortField in rptClientDoc.DataDefController.DataDefinition.Sorts)

        {

        foreach (SortField crSortField in rpt.DataDefinition.SortFields)

        {

        if (RASSortField.SortField.FormulaForm == crSortField.Field.FormulaName)

        {

        if (GRsortIndex >= 0)

        {

        if (crSortField.SortType.ToString() == CrystalDecisions.Shared.SortFieldType.GroupSortField.ToString())

        {

        textBox1 = “Group Sort:\n “;

         

        // don not remove this is to alter sorts only

        ////SortController sortController = rptClientDoc.DataDefController.SortController;

        ////sortController.Remove(GRsortIndex); // Sort of works for Groups – set the sort type to original order

        //try

        //{

        //    // you connot add a No sort, to remove the sort so you have no sort simply delete the sort and then save the report and reopen it. Only way to update the collection.

        //    sortController.Remove(GRsortIndex); // Sort of works for Groups – set the sort type to original order

        //    //sortController.ModifySortDirection(GRsortIndex, CrSortDirectionEnum.crSortDirectionNoSortOrder);

        //    rptClientDoc.VerifyDatabase();

        //}

        //catch (Exception ex)

        //{

        //    btnSQLStatement.Text = “ERROR: ” + ex.Message;

        //}

        //////RASSortField.SortField.Name = @”DistinctCount (Employee_Options.EMPLOYEE Full Name, Employee_Options.EMPLOYEE Hire Date, ‘Monthly’)”;

        // do not remove this is to alter sorts only

         

        IsRpt = false;

        GRsortIndex++;

        flcnt++;

        }

        else

        {

        textBox1 = “Record Sort:\n “;

        }

         

        …..

         

        Code is commented out….

         

        Don

        Add Comment

        Your Answer

        By posting your answer, you agree to the privacy policy and terms of service.