Skip to Content
author's profile photo Former Member
Former Member

change ws parameter at runtime

I am trying to pass a value from my main report into a subreport which uses a .net datasource connected to a WS

the datasource has 4 parameters and I am trying to change them from the main report on the fly. Eg based on the values I am passing in change the data source params for the subreport

I have set my grouping data element as the link field and I linked it to my subreport parameter field but I keep getting errors

any ideas?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 17, 2009 at 03:33 PM

    Hi Hugely

    Can you please let us know the exact error messages you are receiving while trying to link the subreport and the main report?

    Thanks

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 17, 2009 at 04:24 PM

    Hi

    Are you inserting the subreport at runtime of does the subreport exist in the main report?

    Only way to change the SQL is to alter the filtering or setting the table location etc.

    CRPE32 and RDC allowed this but .NET does not. It was simply generating too many support calls by allowing end users to make changes and not properly formatting the SQL.

    You can try creating a data set based on the SQL statement in the report, then setting the report datasource to that data set.

    Also You can apply the filtering by subreport name using this method which should give you the results you are looking for. This is how you would modify the SQL statement and adds the WHERE clause.

    Another option if you are using saved data reports is to apply the filtering to the subreports saved data filter. You run the report to collect all the data required and then export it to RPT format. Open that report up and add the filtering as required.

    Not sure which engine you are using but possible this will fix you issue. Below is how to do this for the subreport and the same code is used for the main report, just change the reference to the reportclientDoc rather than the GetSubreport:

    private void AddParameter(ISCDReportClientDocument reportClientDocument, string fieldName)

    {

    ISCRParameterField newParameterField = new ParameterFieldClass();

    newParameterField.ParameterType = CrParameterFieldTypeEnum.crParameterFieldTypeReportParameter;

    newParameterField.Name = "Check Name";

    u2026u2026u2026u2026u2026

    Hereu2019s the complete routine. Above is how to open the main report and then use the same doc.

    private void AddParameterSB(ISCDReportClientDocument reportClientDocument, string fieldName)

    {

    SubreportClientDocument sb = reportClientDocument.SubreportController.GetSubreport("YourSubreportName.rpt");

    ISCRParameterField newParameterField = new ParameterFieldClass();

    newParameterField.ParameterType = CrParameterFieldTypeEnum.crParameterFieldTypeReportParameter;

    // newParameterField.Name = "p" + fieldName;

    newParameterField.Name = "New Parameter Name";

    newParameterField.ReportName = "YourSubreportName.rpt";

    newParameterField.Type = CrFieldValueTypeEnum.crFieldValueTypeStringField;

    newParameterField.AllowMultiValue = true;

    newParameterField.AllowCustomCurrentValues = false;

    //Fields parameterFields = reportClientDocument.DataDefinition.ParameterFields;

    ISCRField existingParameterField;

    RowsetMetaData rowsetMetaData = new RowsetMetaDataClass();

    Fields fields = new FieldsClass();

    ArrayList defaultValues = new ArrayList();

    // Field field = (Field)dataDefController.FindFieldByFormulaForm("{ASSETS.Owner}");

    fields.Add(sb.DataDefController.DataDefinition.ResultFields.FindField(

    "{YourDB.FieldName}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault));

    sb.DataDefController.ParameterFieldController.SetCurrentValue("YourSubreportName.rpt", "@ExistParameterName1", "");

    sb.DataDefController.ParameterFieldController.SetCurrentValue("YourSubreportName.rpt", "@ExistParameterName2", "");

    // Add as many current values as required

    rowsetMetaData.DataFields = fields;

    RowsetController rowsetController = sb.RowsetController;

    RowsetCursor rowsetCursor = rowsetController.CreateCursor(null, rowsetMetaData, 0);

    // iterate over rows, add unique parameter default values

    while (rowsetCursor.MoveNext())

    {

    Record record = rowsetCursor.CurrentRecord;

    if (!defaultValues.Contains(record[0].ToString()))

    {

    defaultValues.Add(record[0].ToString());

    newParameterField.DefaultValues.Add(record[0].ToString());

    }

    }

    newParameterField.Usage = (int)CrParameterFieldUsageEnum.crParameterFieldUsageInUse;

    newParameterField.IsEditableOnPanel = true;

    newParameterField.IsShownOnPanel = true;

    reportClientDocument.DataDefController.ParameterFieldController.Add((ParameterField)newParameterField);

    reportClientDocument.DataDefController.SavedDataFilterController.SetFormulaText("{YourDB.FieldName } = {?New Parameter Name}");

    }

    What the above does is sets the filtering on the saved data within the report. Rather than setting the DB filter, filter the data within. You may want to do some filtering for the subreport or it may return all records.

    Hope this helps!!

    Regards

    Sourashree

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.