cancel
Showing results for 
Search instead for 
Did you mean: 

How to set default value to a parameter in sub-report using .Net SDK

Former Member
0 Kudos

Hi,

We have a main report and a sub-report. The sub-report has two parameters, one of them has a default value. The main report has only one parameter and it is linked to the non-default parameter in sub-report. When we try to load and export the main report using .Net SDK, we only pass the required parameter to main report. We don't want to pass the 2nd parameter to the sub-report since it should take its default value.

However the code throws a Missing Parameter exception, which is caused by the default parameter from the sub-report.

Is there a way to pass the default to the sub-report?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

DellSC
Active Contributor
0 Kudos

Have you configured the parameter that contains a default as an Optional parameter? (This is an available option for Crystal 2008 and newer).  If not, you need to do this.  That way there should be no issues with the code if you don't give it a value other than the default.

-Dell

Former Member
0 Kudos

Dell, thanks for your answer. I already tried and Optional wouldn't help. It still throws the same exception.

former_member207665
Active Participant
0 Kudos

Hi Pradeep,

What is the behavior when you view the report from the designer? Are you getting prompt for 2 parameters or only one?

What is the version of Crystal reports Designer?

What is the version of .NET SDK Runtimes?

Regards,

Vinit

Former Member
0 Kudos

Thanks Vinit. I am able to loop through the subreports and assign them one by one.

Now I ran into another issue. How can I tell if a parameter in main report is linked to a parameter in sub-report?

var subReportNames =

                cryRpt.ReportClientDocument.SubreportController.GetSubreportNames();

            foreach (var subReportName in subReportNames)

            {

                var defaultValuesSubReport = new Dictionary<string, string>();

                foreach (CrystalDecisions.ReportAppServer.DataDefModel.ISCRParameterField clientParameterFieldDefinition in cryRpt.ReportClientDocument.SubreportController.GetSubreport(subReportName.ToString()).DataDefController.DataDefinition.ParameterFields)

                {

                    foreach (var initialValue in clientParameterFieldDefinition.InitialValues)

                    {

                        var discreetInitialValue = initialValue as CrystalDecisions.ReportAppServer.DataDefModel.ParameterFieldDiscreteValue;

                        if (discreetInitialValue != null)

                        {

                            defaultValuesSubReport.Add(clientParameterFieldDefinition.Name, discreetInitialValue.Value);

                            //var defaultValue = discreetInitialValue.Value; //Use initial value anyway you would like to. In our case, we stored it and passed to our ExtJs UI to populate in the interface.

                        }

                    }

                }

                foreach (var defaultValue in defaultValuesSubReport)

                {

                    cryRpt.SetParameterValue(defaultValue.Key, defaultValue.Value, subReportName.ToString());

                }

            }

Answers (0)