cancel
Showing results for 
Search instead for 
Did you mean: 

Can't find Default Value for Parameter

08-01-2013 5:39 PM
1125 views 5 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

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.

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

0 Likes

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

Former Member
0 Likes

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):

  • getParameterFields has a parameter called "rpt" that is never used and the method refers to "rptClientDoc" which is never defined. I assume they are meant to be the same.
  • The call isParameterDynamic(rpt, 0, YorN); is not going to set YorN. Variables in C# are passed by value. You need to store the return value if you want to make use of it. YorN is also a really poor name for a variable.

There may be more issues, but I didn't actually attempt to run that code.

0 Likes

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

Former Member
0 Likes

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:

  • I have a file called documentation.html located at C:\Program Files (x86)\Crystal Reports for Visual Studio\Collaterals\Docs\en. It tells me to go to the help.sap.com portal and click on "all products" on the left. There is no "all products" on the left. Clearly the site has been reorganized since this file was created.
  • Under C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\Crystal Reports 2011\HelpFiles I have a bunch of .cab files. Maybe the help is in there? They're all dated 1/6/2013 however so I have no plans to try and unpack them to see if that's where the SDK docs are hiding. On the other hand, SP6 came out several weeks ago and the download page at http://scn.sap.com/docs/DOC-7824 still lists the fixed issues as "coming" (although it previously said "coming soon" so perhaps this is an improvement?).

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.

0 Likes

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...

http://help.sap.com/analytics

Then All Products

Answers (0)