on 03-17-2009 3:28 PM
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.