Link to home
Start Free TrialLog in
Avatar of GaryRasmussen
GaryRasmussenFlag for United States of America

asked on

Error when saving parameter values as default values

I have a C# Windows fom application that has a .NET Crystal Report Viewer.  The application opens an XML file with all the information it needs in order to display the report.  It will also save the parameter values used as default values in the report if the user wants it to.  I have one report that is giving me an error that I am unable to find anything about on the web.

System.Runtime.InteropServices.COMException (0x80042009): The parameter field default values contain some field values that are not valid.  They must be discrete values only.
   at CrystalDecisions.ReportAppServer.Controllers.ParameterFieldControllerClass.Modify(Object OldParameterField, ParameterField NewParameterField)
   at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.ApplyDefaultValues(ParameterValues defaultValue)
   at RocktonReportEngine.ReportForms.CrystalReport.ProcessReportParameters()
 
The report has 2 parameters.  A discrete parameter and a range parameter.  I have lots of reports that have both types of parameters but this report is the only one that it is causing the error so I wonder if there is something different about this report but I don't know what to look for.  Something is different about this report that my code is not accounting for.

I would be glad to include my code but for now I was just wondering if anyone has seen this before and or what it means.

Thanks!
Avatar of Mike McCracken
Mike McCracken

I have never seen that.

What values are you saving for the parameters?

How do you pass them to the report?

mlmcc
Avatar of GaryRasmussen

ASKER

If you can help me out with this problem it would be fantastic!

I have attached my code in a doc that processes each parameter found in the XML and the XML that deals with parameters looks like this:

-<Parameters>-<Parameter><Name>Sales Date Range</Name>-<ParameterValues>-<RangeValue><StartValue>5/1/2012</StartValue><EndValue>5/31/2012</EndValue></RangeValue></ParameterValues></Parameter>-<Parameter><Name>Item Number</Name>-<ParameterValues><DiscreteValue>100XLG</DiscreteValue></ParameterValues></Parameter></Parameters>
Code-for-processing-parameters.docx
I would start with making sure that you are always dealing with discrete and range parameters.

did you try to replace:
"else //Range Value"

with
else if (valuesNode.ChildNodes(i).Name == "RangeValue")  //replace "(" in (i) with "[", it is not accepted by the comment editor
{
...
}
else
   throw an error here


may be the xml was edited and "DiscreteValue" was changed to something similar but not the same. Then the "if" will try to process the parameter as a range value instead of discrete value . Can you post the xml for the parameter which is failing ?
The XML is correct and you can see it in the message above.

dated by: GaryRasmussenPosted on 2012-05-21 at 21:04:16ID: 37995511
What error are you getting?

Are the parameters static or dynamic?

mlmcc
The 2 parameters in Crystal Reports are Static.

The error I am getting is:

System.Runtime.InteropServices.COMException (0x80042009): The parameter field default values contain some field values that are not valid.  They must be discrete values only.
   at CrystalDecisions.ReportAppServer.Controllers.ParameterFieldControllerClass.Modify(Object OldParameterField, ParameterField NewParameterField)
   at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.ApplyDefaultValues(ParameterValues defaultValue)
   at RocktonReportEngine.ReportForms.CrystalReport.ProcessReportParameters()
Which line rises the error ?


Try to clear the values collections after this line:
                    //Get a collection of the current values collection
                    ParameterValues currentValues = parameterFieldDef.CurrentValues;

I don't have a project to check the exact syntax but it is something like this:
parameterFieldDef.DefaultValues.Clear()
parameterFieldDef.CurrentValues.Clear()

Why  default values are applied just in case custom values are allowed , but current values are always applied ?
I thought you had to apply the current values in order for the peport to use the parameter values.  That is why they are always applied becuase the user always wants the parameter values applied if they are passing them in.  Is that not correct?

Saving the values as default values is optional.
My understanding is that AllowCustomValues is just a flag for Crystal interface to allow manual insert or selection from a list. Anyway this cannot cause the error, I was just curious.

Did you try to clear the collections before to apply them and on what line is the error ?
I will try that ASAP.  I am still unable to run the customers report in Crystal in my environment so I have no way to test yet.  The error message was what displayed on the customer's machine in their environment.

I can't find anything on that error anywhere.
There are also strange "-" characters in the xml. Is this from IE when you coppied the data or they exist in the xml file ( or string)

-<Parameters>-<Parameter><Name>Sales Date Range</Name>-<ParameterValues>-
Sorry no, they got copied in from IE.  I have checked and the XML is clean
It ie erroring on this line

//Apply the remembered values to the defaultvalues collection
parameterFieldDef.ApplyDefaultValues(defaultValues);

Do you have a code example of how default values should be saved to the report? Perhaps I am just doing it wrong?
I think what my code was actually doing was trying to save the parameter values back to the report as default values so that from that point on, the user would not need to enter parameter values when ever they opened the report.

However the goal is not to do anything to the report itself but make it so after a user has displayed the report and they hit refresh, the viewer does not ask them to enter parameters again.  So it is a session thing and not a report thing.

Do you know how that is accomplished?
I am not sure that the default values support ranges.
I think I found what I need and am testing it now.

ReuseParametersOnRefresh
well poop.  The crystal report viewerr I am using does not have that property.  Most people that do have it say it doesn't work and still prompts the user shen refresh is clicked.  Do you know of any way to make the report viewer not prompt you for parameter values and just use the previous values when refrech is clicked?
SOLUTION
Avatar of vasto
vasto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Vasto!