cancel
Showing results for 
Search instead for 
Did you mean: 

Where did m_Report->PutEnableParameterPrompting(false); go?

anders_gustafsson
Participant
0 Kudos

Ie, it used to be there in CR9, but is now absent in CR XI R2. There is an option to set parameter prompting in the Viewer, but not when printing to a printer. I would like to set it so that the report just prints happily even if one or more parameters are not provided. That was the case in CR9, but now the entire report just fails to print unless I provide all parameters.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Anders,

Which SDK are you using? The CR .NET SDK or the CR RDC SDK? I wasn't able to find a "PutEnableParameterPrompting" property for the .NET SDK or the RDC object model in the [CR XI R2 Developer Library|http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/devsuite.htm]. I just found an "EnableParameterPrompt" property.

Was the parameter prompting property working with an earlier patch level for CR XI R2? Did it start failing after applying a patch? Or are you migrating to CR XI R2 from CR 9 right now?

Once you clarify which SDK and object model you're using someone might have some suggestions.

Sincerely,

Dan Kelleher

anders_gustafsson
Participant
0 Kudos

Sorry about that. I went from CR9 and the legacy API to CR XI R2 NET. The app is C++ Managed.

Thanks for the link. I was not aware of that. I have always used the helpfiles (crsdk_net_apiRef_12_en.chm). IS there any way to apply this to the actual Report object?

Edit:

or rather is there any way to get the report to print and just use default values for parameters if parameters are missing?

Edited by: Anders Gustafsson on Jan 26, 2012 4:15 PM

0 Kudos

Hi Anders,

On your form where you dropped the viewer onto click on the Viewer and in the Properties page you'll find the

ReuseParameterValuesonRefresh = True/false.

If you use the Object Browser you'll find:

public System.Boolean ReuseParameterValuesOnRefresh { get; set; }

Member of CrystalDecisions.Windows.Forms.CrystalReportViewer

Summary:

Gets or sets whether saved parameter values are reused when the report is refreshed, or whether the user will be prompted to select values.

CrystalReportViewer->ReuseParameterValuesOnRefresh = true;

Don

Edited by: Don Williams on Jan 26, 2012 8:07 AM

Adam_Stone
Active Contributor
0 Kudos

The parameter prompting functionality is limited to when using the viewer. You will need to make sure that all parameters have a current value set, it will not pull the default value if no value is set. The default value is essentially just used by the viewer to pre-populate the prompt page. You could look at changing the prompts to be optional, that functionality was added in CR2008 (12.x)

anders_gustafsson
Participant
0 Kudos

OK. And that means setting parameters programmatically? Ie, there is no way to provide default parameters in the .rpt file itself?

Adam_Stone
Active Contributor
0 Kudos

Correct. In the report you can set Default values, but in order to execute a report (print, view, export) you need to populate the current values collection. The default values do not get put into the current values collection automatically.

0 Kudos

And when you do upgrade to CR for VS 2010 here's how you get them, sorry it's C# but should be about the same:

btn* is the name of the text box I use to show the values. The Default value is the value you selected in the middle of the Parameter UI, not the one in the lower area called Default, that is legacy name and no way to get that value.


private void getParameterFields(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt)
{
    string textBox1 = String.Empty;
    string textBox2 = String.Empty;
    string MyObjectType = ReportObjectComboBox1.SelectedItem.ToString();
    btnReportObjects.Text = "";
    int x = 0;
    int z = 0;

    foreach (CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramFields in rptClientDoc.DataDefController.DataDefinition.ParameterFields)
    {
        textBox1 = paramFields.LongName.ToString();
        btnReportObjects.Text += textBox1;
        btnReportObjects.AppendText(" = ");

        CrystalDecisions.ReportAppServer.DataDefModel.Fields flds;
        flds = rptClientDoc.DataDefController.ParameterFieldController.GetPromptParameterFields(null);

        CrystalDecisions.ReportAppServer.DataDefModel.ParameterField pfld1 = (CrystalDecisions.ReportAppServer.DataDefModel.ParameterField)flds[z];
               
        try
        {
            CrystalDecisions.ReportAppServer.DataDefModel.Value val = (CrystalDecisions.ReportAppServer.DataDefModel.Value)pfld1.InitialValues[0];
            btnReportObjects.AppendText(pfld1.InitialValues.ToString());
            btnReportObjects.AppendText(" is Initial Value \n");
        }
        catch
        {
            btnReportObjects.AppendText("No Initial Value \n");
        }

        if (paramFields.ValueRangeKind == CrParameterValueRangeKindEnum.crParameterValueRangeKindDiscrete)
        {
            try
            {
                CrystalDecisions.ReportAppServer.DataDefModel.ParameterFieldDiscreteValue paramField1;
                paramField1 = (CrystalDecisions.ReportAppServer.DataDefModel.ParameterFieldDiscreteValue)paramFields.DefaultValues[0];
                btnReportObjects.AppendText(paramField1.Value);
                btnReportObjects.AppendText(" is Default Value \n");
                z++;
            }
            catch
            {
                btnReportObjects.AppendText("No Default Values \n");
            }
        }
        else
        {
            int y = 0;
            CrystalDecisions.ReportAppServer.DataDefModel.ParameterField pfld = (CrystalDecisions.ReportAppServer.DataDefModel.ParameterField)rptClientDoc.DataDefinition.ParameterFields[x];

            int pCount = pfld.DefaultValues.Count;
            CrystalDecisions.ReportAppServer.DataDefModel.ISCRValues currentvalues;
            currentvalues = pfld.CurrentValues;
            flds = rptClientDoc.DataDefController.ParameterFieldController.GetPromptParameterFields(null); 

            btnReportObjects.AppendText("Range Values:\n ");

            foreach (CrystalDecisions.ReportAppServer.DataDefModel.ISCRValue RangeVal in pfld.DefaultValues)
            {
                CrystalDecisions.Shared.ParameterDiscreteValue oValue = (CrystalDecisions.Shared.ParameterDiscreteValue)rpt.DataDefinition.ParameterFields[x].DefaultValues[y];
                btnReportObjects.AppendText(oValue.Value.ToString());
                // Get the original default values
                ParameterFieldDefinition boParameterFieldDefinition;
                ParameterValues boParameterDefaultValues;
                //ParameterDiscreteValue boParameterDiscreteValue;
                bool myDefault;
                myDefault = rpt.DataDefinition.ParameterFields[x].HasCurrentValue;
                boParameterFieldDefinition = rpt.DataDefinition.ParameterFields[0];
                boParameterDefaultValues = rpt.DataDefinition.ParameterFields[0].CurrentValues;

                btnReportObjects.AppendText("\n ");
                y++;
            }
        }

        btnReportObjects.AppendText(" 'End' \n");
        x++;
    }
}

Don

anders_gustafsson
Participant
0 Kudos

Thanks for the code-snippet. When I call a report from any of my classes there is no problem, because I know what the report expects. Problems arise in what we call "The print Queue" where you can define a list of reports to be printed by selecting a menu item. The routine just picks each rpt and prints it and while the core set of params is pretty uniform, some reports can have additional params. Those can be set in the queue as well, but for reports that have tens or so additional params it becomes tedious.

I guess the best is to add a function that checks the parameters in the report and provides values for those that have no value set.

anders_gustafsson
Participant
0 Kudos

This seems to do the trick (Exception handling removed for clarity)


int CLpReportJob::SetParameterDefaultValues()
{
	int ret = 0;
	CrystalDecisions::Shared::ParameterField ^pf;
	CrystalDecisions::Shared::ParameterFields ^pfs;

	String ^ss_defaultString = gcnew String("default");
	String ^ss_zeroString = gcnew String("0");
	pfs = m_Report->ParameterFields;
    for (int i = 0; i < pfs->Count; i++)
	{
		pf = pfs<i>;
		pf->CurrentValues->Count;
		TRACE("\nParm: %s, count: %d",pf->Name, pf->CurrentValues->Count);
		if(pf->CurrentValues->Count == 0)
		{
			if (pf->ParameterValueKind == ParameterValueKind::StringParameter)
				m_Report->SetParameterValue(pf->Name, ss_defaultString);
			if (pf->ParameterValueKind == ParameterValueKind::NumberParameter)
				m_Report->SetParameterValue(pf->Name, ss_zeroString);
			++ret;
		}
	}
	delete ss_defaultString;
	delete ss_zeroString;
	return ret;
}

anders_gustafsson
Participant
0 Kudos

Just realised that it is bad karma to muck with parms in subreports that link to the main report, so better exclude all "Pm":


int CLpReportJob::SetParameterDefaultValues()
{
	int ret = 0;
	CrystalDecisions::Shared::ParameterField ^pf;
	CrystalDecisions::Shared::ParameterFields ^pfs;
	String ^ss_defaultString = gcnew String("default");
	String ^ss_zeroString = gcnew String("0");
	CString Temp;
	pfs = m_Report->ParameterFields;
    for (int i = 0; i < pfs->Count; i++)
	{
		pf = pfs<i>;
		pf->CurrentValues->Count;
		TRACE("\nParm: %s, count: %d",pf->Name, pf->CurrentValues->Count);
		Temp = pf->Name->ToString();
		if(pf->CurrentValues->Count == 0 && Temp.Left(2) != "Pm")
		{
			try 
			{
				if (pf->ParameterValueKind == ParameterValueKind::StringParameter)
					m_Report->SetParameterValue(pf->Name, ss_defaultString);
				if (pf->ParameterValueKind == ParameterValueKind::NumberParameter)
					m_Report->SetParameterValue(pf->Name, ss_zeroString);
				++ret;
			}
			catch (System::Exception ^ e) 
			{
				TRACE("SetParameterDefaultValues() Exception %s", e->Message);
			}
		}
	}
	delete ss_defaultString;
	delete ss_zeroString;
	return ret;
}

0 Kudos

Hi Anders,

You are correct, as you noticed the Parameter Collection is off the whole report and it does include the subreport links which are parameters. So do filter those out.

You will also notice in the Parameter UI in the Designer there are 2 places you can put parameters values. Don't set them in the lower box titled Value Options: Default Values. That is the legacy place and we don't read that value in the collection. Us the "Value" for your default values, located in the middle of the form.

You can also use RAS with Parameters: CrystalDecisions.ReportAppServer.Controllers.ParameterFieldController

Thanks again

Don

Answers (0)