Welcome to MSDN Blogs Sign in | Join | Help
My Office Accounting report’s aging filters need to add new columns

I just got this question:

 

“The problem is that I am creating a new custom report using the INativeReportV2 interface.  I am trying to apply Aging Options Filter to the report.  The problem is, how I do capture those values in the CreateDesign method?  The CreateDesign method only accepts the IReportDesign parameter, it does not pass in the IReportFiltersV2 parameter.  If you can provide any advice on this issue, I’d really appreciate it.”

 

The only answer I could find is: … you don’t

 

You can’t do that in the CreateDesign method that is. You will have to cheat and create the columns in another method where you do have access to the IReportFiltersV2 parameter.

 

CreateData would be a good option for such a method – but then I don’t have access to the IReportDesign !?!

 

Well you will have to cheat a bit and keep a reference to the design in a class variable, the reference can be set in the CreateDesign method.   
Posted: Monday, August 11, 2008 8:41 PM by Jorn

Comments

richabreu said:

Hello Jorn,

Your post was a big help, thank you.  But now I have another question that is related to this post.  It seems that when the design is changed on the fly, the column sequence is affected.  

For example, the report starts out with the following columns:  "Invoice #", "Due Date", "1-30", "31-60", "61-90", "Over 90".

If I change to aging interval to 20 days the columns become: "1-20", "21-40", "41-60", "61-80", "81-90", "Invoice #", "Due Date", "Over 90".

I am creating the report columns in the following order: "Invoice #", "Due Date" and then looping through the aging interval to create the other columns.

It appears like the report interface is displaying new columns first. Is there a way where I can refresh the report interface or control the sequence order?

Thanks in advance.

Rich

# August 13, 2008 11:42 AM

Jorn said:

Interesting, I do not see that behavior. Any chance you can share your code?

# August 13, 2008 12:37 PM

richabreu said:

Jorn, here are some code snippets related to the report design:

public void CreateDesign(IReportDesignV2 iReportDesign)

{

   // Check object references

   if (iReportDesign == null)

       return;

   // Add a title to the report

   iReportDesign.ReportHeader.ReportTitle.Text = this.reportTitle;

   iReportDesign.ReportColumns.CreateReportColumn("Type", "Type", ReportColumnType.RowLabel, ReportColumnDataType.Text);

   iReportDesign.ReportColumns.CreateReportColumn("PrimaryContact", "Primary Contact", ReportColumnType.Data, ReportColumnDataType.Text);

   iReportDesign.ReportColumns.CreateReportColumn("Phone", "Customer Phone", ReportColumnType.Data, ReportColumnDataType.Text);

   groupidColumn = iReportDesign.ReportColumns.CreateReportColumn("GroupId", "GroupId", ReportColumnType.GroupID, ReportColumnDataType.NumberInt);

   iReportDesign.ReportColumns.CreateReportColumn("Date", "Invoice Date", ReportColumnType.Data, ReportColumnDataType.Date);

   iReportDesign.ReportColumns.CreateReportColumn("Number", "No.", ReportColumnType.Data, ReportColumnDataType.Text);

   iReportDesign.ReportColumns.CreateReportColumn("ReferenceNumber", "Reference", ReportColumnType.Data, ReportColumnDataType.Text);

   iReportDesign.ReportColumns.CreateReportColumn("Void", "Void", ReportColumnType.Data, ReportColumnDataType.Boolean);

   iReportDesign.ReportColumns.CreateReportColumn("PaymentTerm", "Payment Term", ReportColumnType.Data, ReportColumnDataType.Text);

   iReportDesign.ReportColumns.CreateReportColumn("DueDate", "Due Date", ReportColumnType.Data, ReportColumnDataType.Date);

   iReportDesign.ReportColumns.CreateReportColumn("Amount", "Amount", ReportColumnType.Data, ReportColumnDataType.Currency);

   iReportDesign.ReportColumns.CreateReportColumn("Total", "Total", ReportColumnType.Data, ReportColumnDataType.Currency);

   iReportDesign.ReportColumns.CreateReportColumn("Current", "Current", ReportColumnType.Data, ReportColumnDataType.Currency);

   globalReportDesign = iReportDesign;

}

public DataView CreateData(IReportFiltersV2 reportFilters, IReportEngineV2 engine)

{

   //------Passes retrieved filter values (code not shown) into a method and accesses a custom stored procedure (similar to spRptArAgingQuickZoom) and populates DataTables------------------

   AccessStoredProc(asofValue, showvoidValue, amountoperatorValue, nameValue, namelistValue, customergroupValue, customergrouplistValue, amountValue, agingperiodValue, agingintervalValue, engine);

   //------Loops and creates new aging columns based on aging information ------------------------------------------------------------------------

   for (int i = 1; i <= agingperiodValue; i += agingintervalValue)

   {

       int j = i + agingintervalValue - 1;

       if (j > agingperiodValue)

           j = agingperiodValue;

       string columnname = "#" + i + "#" + j + "#";

       string columncaption = i + " - to - " + j;

       globalReportDesign.ReportColumns.CreateReportColumn(columnname, columncaption, ReportColumnType.Data, ReportColumnDataType.Currency);

   }

   globalReportDesign.ReportColumns.CreateReportColumn("Over#" + agingperiodValue + "#", "Over " + agingperiodValue, ReportColumnType.Data, ReportColumnDataType.Currency);

   //------Creates a DataView from fieldsTable, valuesTable and extendedvaluesTable DataTables populated from the stored procedure

   DataView view;

   foreach (DataRow row in fieldsTable.Rows)

       if ((row["ParentColumnId"].ToString() != ""))

           valuesTable.Columns.Add(row["ColumnName"].ToString(), typeof(Decimal));

   foreach (DataRow extendedvaluesRow in extendedvaluesTable.Rows)

   {

       DataRow[] fieldRow = fieldsTable.Select("Identification = '" + extendedvaluesRow["ColumnId"].ToString() + "'");

       DataRow[] valuesRow = valuesTable.Select("RowId = '" + extendedvaluesRow["RowId"].ToString() + "'");

       if (valuesRow != null)

       {

           valuesRow[0][fieldRow[0]["ColumnName"].ToString()] = extendedvaluesRow["Amount"];

       }

   }

   view = valuesTable.DefaultView;

   return view;

}

Let me know if this doesn't make sense or if I am doing something wrong.

Thanks.

# August 13, 2008 4:13 PM

Jorn said:

Now I see it…

Ok, this is the problem with cheating :o(

I doubt you will get this working perfectly, I can offer workarounds but that’s about it…

The problem is that we try to reapply the position of the column when the report is refreshed, this is done by column name. Any column that was not there before will be put up front.

The workaround is to add a number of columns always (for example 50 columns) and then hide the ones that are not used. The downside is that the user can see these columns under Modify report/Columns. Example:

Caption Name Visible

1 – to - 30 #1 Yes

1 – to – 60 #2 Yes

1 – to – 90 #3 Yes

Over 90 #4 Yes

              #5 No

              #6 No

              #7 No

Etc

After changing the interval it would look like this:

Caption Name Visible

1 – to - 20 #1 Yes

21 – to – 40 #2 Yes

41 – to – 60 #3 Yes

61 – to – 80 #4 Yes

81 – to – 90 #5 Yes

Over 90 #6 Yes

              #7 No

# August 13, 2008 5:44 PM

richabreu said:

Hi Jorn,

Again thanks for your help.  Your solution solved the column order problem.  But I now have a new problem.  It seems that I can't change the visibility of a column once it has been intially loaded into the report.  So in your example above, if column #5 is initially not visible, it stays not visible after an aging option is selected.  I have stepped through the code and confirmed that the ReportColumnType is correct and IReportColumnV2.Visible is true and it still comes up as not visible in the report.  

Is there a way to refresh the report viewer itself or to delete all of the columns and then recreate them so the report sees them all as new?

Thanks again,

Rich

# August 14, 2008 3:55 PM

richabreu said:

As a quick follow-up to my question.  How does the A/R Aging Detail report do this, because that is exactly the type of column behavior I am trying to duplicate.  Thanks.

# August 14, 2008 3:59 PM

Jorn said:

Ouch, yet another side effect from cheating (sorry I didn't think about this before)

It's really the same cause as before, we apply the properties from before making any width, index, visible etc. properties the same as before.

I need to think about this a bit, right now I do not see a way around it.

How do we do it internally? Well the external API is highly simplified compared to the internal one (generally you should be happy about this) We only use the external API for features that ship as add-ins, as these reports did not have the aging filters we have not run into these problems.

Internally we can mark these 'dynamic' columns with a special property making them immune to the problems you have hit, you will also notice that the dynamic columns does not show up under [modify report]

I’ll keep thinking, but here is an idea (I haven’t tried it) try making the columns you do not want to see ReportColumnType.NotVisible instead of ReportColumnType.Data…

# August 14, 2008 7:44 PM

richabreu said:

Jorn,

I am using ReportColumnType.NotVisible for columns that are initially not used, and then changing it to ReportColumnType.Data when I need them, but they stay invisible.

Thanks,

Rich

# August 15, 2008 1:50 PM

Jorn said:

Ok, now I tried it, and yes you are right. It comes down to the same issue...

We need to change the Office Accounting client for your report to work right.

All of the workarounds have issues for the user:

Add columns dynamically:

This will add the columns in the beginning of the column list

Setting visible=false or NotVisible

will have the effect that the user may have to make the columns visible manually

Leave the unused columns visible with no data and no caption.

This may be the best option for the user as the data will be available as soon as they change the filter. The down side is clear: the report will not look professional with the empty columns.

I’m Sorry, but is looks like we can’t get any closer to a real solution right now! (I’ll keep thinking)

# August 15, 2008 3:58 PM
Anonymous comments are disabled
Page view tracker