As discussed in http://scn.sap.com/thread/3277398 I cannot find the default value using SAP Crystal Reports, developer version for Microsoft Visual Studio 13.0.6. While the answer in that discussion is marked "helpful" it doesn't actual answer the original question in that discussion and that's exactly the problem I'm now running into.
There is nothing that looks like it should have that value, and debugging does not show anything that actually contains that value. According to the discussion at http://scn.sap.com/thread/2036996 this issue was noted at about 2 years ago, and was scheduled to be fixed. The first linked discussion seems to indicate that it has been fixed, but my testing doesn't show it as being available, and almost every discussion of this topic seems to devolve into a misunderstanding that the questioner is asking about how to get items from the static list of values. That is not what I am trying to do.
Is it possible to get the single "Default Value" that has been defined for the parameter and make use of that in my .Net code. Or, should I start looking into work-arounds, such as using the first item in the static values list and telling our clients they need to edit all of their reports to put the default values there?
Thanks.
Request clarification before answering.
Hi Colin,
You can get both:
btnReportObjects is a text box....
private void getParameterFields(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt)
{
string textBox1 = String.Empty;
string textBox2 = String.Empty;
string MyObjectType = ReportObjectComboBox1.SelectedItem.ToString();
btnReportObjects.Text = "";
if (rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count > 0) //there are parameters
{
btnCount.Text = rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count.ToString();
foreach (CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramfield in rptClientDoc.DataDefController.DataDefinition.ParameterFields)
{
switch (paramfield.ValueRangeKind)
{
case CrParameterValueRangeKindEnum.crParameterValueRangeKindDiscrete:
{
getDiscreteValues(paramfield);
break;
}
case CrParameterValueRangeKindEnum.crParameterValueRangeKindDiscreteAndRange:
{
getRangeAndDiscreteValues(paramfield);
break;
}
case CrParameterValueRangeKindEnum.crParameterValueRangeKindRange:
{
getRangeValues(paramfield);
break;
}
}
}
}
}
public Boolean isParameterDynamic(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt, int iCnt, bool YorN)
{
if (rpt.DataDefinition.ParameterFields[iCnt].Attributes != null && rpt.DataDefinition.ParameterFields[iCnt].Attributes.ContainsKey("IsDCP"))
{
Hashtable objAttributes = rpt.DataDefinition.ParameterFields[iCnt].Attributes;
YorN = (Boolean)objAttributes["IsDCP"];
return YorN;
}
return YorN;
}
private void getDiscreteValues(CrystalDecisions.ReportAppServer.DataDefModel.ISCRParameterField paramfield)
{
string textBox1 = String.Empty;
string name = paramfield.Name;
int currValCount = paramfield.InitialValues.Count;
int defValCount = paramfield.DefaultValues.Count;
bool YorN = false;
if (defValCount > 0) //this parameter has default values
{
foreach (ParameterFieldDiscreteValue discreteDefaultVal in paramfield.DefaultValues)
{
btnReportObjects.AppendText(paramfield.Name.ToString());
textBox1 = ": " + discreteDefaultVal.Value.ToString();
btnReportObjects.Text += textBox1;
btnReportObjects.AppendText("\n");
if (currValCount > 0)
{
foreach (ParameterFieldDiscreteValue CurrentInitialVal in paramfield.InitialValues)
{ // Always only going to be 1
textBox1 = "Default Value: " + CurrentInitialVal.Value.ToString();
btnReportObjects.Text += textBox1;
btnReportObjects.AppendText("\n");
}
}
if (discreteDefaultVal.Description != null)
{
textBox1 = "Description: " + discreteDefaultVal.Description.ToString();
}
else
textBox1 = "Description:";
btnReportObjects.Text += textBox1;
btnReportObjects.AppendText("\n");
}
}
else
{
isParameterDynamic(rpt, 0, YorN);
btnReportObjects.AppendText(paramfield.Name.ToString());
if (YorN)
{
btnReportObjects.AppendText(": No Initial Value \n");
}
else
{
string myPrefix = paramfield.Description;
btnReportObjects.AppendText(": Dynamic Cascading Parameter ( LOV )\nBased on field: " + paramfield.FormulaForm + "\n"); // paramfield.Description.Remove(0, 6) + "\n");
}
}
}
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It looks like what I need is
((ParameterFieldDiscreteValue)paramfield.InitialValues[0]).Value
Thanks.
I should note however, that the sample you provided has a number of bugs in it (provided for the benefit of future searchers):
There may be more issues, but I didn't actually attempt to run that code.
Great. Never said it was code complete, just a sample on how to... There is a lot more to that process, you should handle each type...
Rpt = ReportDocument ( Engine )
rptCleintDoc = ReportClientdocument ( RAS )
For Future, check the Obejct Browser, you'll find a lot of info in there as well as the SDK help file. It is all in there.
Don
In this case the object browser was of zero help, because there is no way I would have ever guessed that the InitialValues array was the same thing as the Default Value single-entry UI element.
As for the documentation:
Maybe old and out of date documentation is just SOP for SAP.
I appreciate the work you and Ludek do to support CR on these forums, especially as it sounds like the people responsible for creating and fixing the software are actively hostile towards acknowledging bugs and shortcomings. I spent the first 15+ years of my career without needing to touch CR and if I never have to see it again it will be too soon.
No hostility from our Developers, I work with them daily and they are a bunch of great people doing what needs to be done...
Too bad for what ever reason after 15 years you have to use it now.... Doesn't matter what we say or
do you are going to find a fault somewhere...
Good luck in your future endeavors...
Then All Products
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.