on 10-30-2015 12:28 PM
I am struggling to get the passing of multiple discrete values to a parameter field to work. Single discrete and single ranged parameters are working fine, but despite trying all examples I can find (and there's not many) I can't get it to work. Can anyone see what is going wrong in my code below, please?
This is running against CR Server 2013 and it is lines 36-45 that are the issue. The code steps through the parameters found in the report and looks for URL/Form values with matching names. The multiple value capable fields are supplied with comma delimited lists of strings in the URL/Form values.
Private Sub DatabaseLogon_unmanagedRAS()
Dim mySampleReportPath As String = Request("rpt__rpt")
Dim path As Object = CType(mySampleReportPath, String)
Dim rptFile As String = path.Substring(8)
Dim databaseUserName As String = Request("rpt__un")
Dim databasePassword As String = Request("rpt__pw")
Dim rcd As New ReportClientDocumentClass()
Dim pfld As String
Dim pfldName As String
Dim crMainReportParameterFields As Fields
Dim crField As Field
Dim arrKeys() As String
Dim newVal As ParameterDiscreteValue
Dim crDiscreteVal As CrystalDecisions.Shared.ParameterDiscreteValue
rcd.ReportAppServer = "localhost:6420"
rcd.Open(rptFile, 0)
rcd.DatabaseController.logon(databaseUserName, databasePassword)
crMainReportParameterFields = rcd.DataDefinition.ParameterFields
For Each crField In crMainReportParameterFields
pfldName = crField.Name.ToString
Try
Select Case crField.ValueRangeKind
'Ranged parameter.
Case 0
Dim crRangeVal As ParameterFieldRangeValue = New ParameterFieldRangeValue()
pfld = Request(pfldName)
arrKeys = pfld.Split("|")
crRangeVal.BeginValue = arrKeys(0)
crRangeVal.EndValue = arrKeys(1)
crRangeVal.LowerBoundType = RangeBoundType.BoundInclusive
crRangeVal.UpperBoundType = RangeBoundType.BoundInclusive
rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crRangeVal)
'Discrete parameter.
Case 1
If crField.AllowMultiValue Then ' multiple values
Dim crParameterValues As ParameterValues = New ParameterValues()
pfld = Request(pfldName)
arrKeys = pfld.Split(",")
For Each multiVal As String In arrKeys
crDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
crDiscreteVal.value = multiVal.toString()
crField.CurrentValues.Add(crDiscreteVal)
Next
Else ' single value
crDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
crDiscreteVal.Value = Request(pfldName)
rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crDiscreteVal)
End If
End Select
Catch ex As Exception
Response.Write("<b><u>The report viewer has encountered an error:</u></b><br><br>")
Response.Write(ex.Message)
Response.Write("Stack Trace: " & vbCrLf & ex.StackTrace)
rcd.Close()
Finally
'do cleanup
End Try
Next
'Debug_showParams(crMainReportParameterFields)
myCrystalReportViewer.ReportSource = rcd
myCrystalReportViewer.HasRefreshButton = true
End Sub
Hi Dave,
What SDK package are you using?
What is the actual error you are getting?
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's the assembly references from my web.config file:
<compilation defaultLanguage="vb" debug="true">
<assemblies>
<add assembly="CrystalDecisions.Enterprise.Viewing.ReportSource, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ObjectFactory, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.CrystalReports.TemplateEngine, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Enterprise.Framework, Version=14.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Enterprise.InfoStore, Version=14.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.Shared, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
<add assembly="CrystalDecisions.ReportAppServer.Controllers, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
<add assembly="CrystalDecisions.ReportAppServer.CommonObjectModel, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
<add assembly="CrystalDecisions.ReportAppServer.ReportDefModel, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
<add assembly="CrystalDecisions.ReportAppServer.DataDefModel, Version=14.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
</assemblies>
</compilation>
I'm not actually seeing any errors at all, just a report viewer with a completely blank area where the report preview should be.
Unfortunately, that is an unrelated issue. I have many reports that are working correctly, it is only when trying to pass a multiple discrete value parameter to a report that the issue occurs. So far I am unable to find any kind of definitive examples on how this should be coded... the official documentation is very lacking in this regard, simply saying you can have multiple value parameters,. but not actually explaining how to populate them.
If anyone has found a working example for this, I would love to see it... all the examples I've tried so far simply do not work.
Dave, it boils down to
Dim currentParameterValues As ParameterValues = New ParameterValues()
Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
Looping through your multiple values doing:
---
myParameterDiscreteValue.Value = submittedValue.ToString()
currentParameterValues.Add(myParameterDiscreteValue)
---
and then,
myParameterFieldDefinition.ApplyCurrentValues(currentParameterValues)
Thanks for that Ido, I have now applied that and tried it, but still getting an error. My loop now looks like this:
- rcd.Open(rptFile, 0)
- rcd.DatabaseController.logon(databaseUserName, databasePassword)
- crMainReportParameterFields = rcd.DataDefinition.ParameterFields
For Each crField In crMainReportParameterFields
pfldName = crField.Name.ToString
Try
Select Case crField.ValueRangeKind
'Ranged parameter.
Case 0
Dim crRangeVal As ParameterFieldRangeValue = New ParameterFieldRangeValue()
pfld = Request(pfldName)
arrKeys = pfld.Split("|")
crRangeVal.BeginValue = arrKeys(0)
crRangeVal.EndValue = arrKeys(1)
crRangeVal.LowerBoundType = RangeBoundType.BoundInclusive
crRangeVal.UpperBoundType = RangeBoundType.BoundInclusive
rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crRangeVal)
'Discrete parameter.
Case 1
If crField.AllowMultiValue Then
Dim currentParameterValues As ParameterValues = New ParameterValues()
Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
pfld = Request(pfldName)
arrKeys = pfld.Split(",")
For Each multiVal As String In arrKeys
myParameterDiscreteValue.Value = multiVal.ToString()
currentParameterValues.Add(myParameterDiscreteValue)
Next
crField.ApplyCurrentValues(currentParameterValues)
Else
crDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
crDiscreteVal.Value = Request(pfldName)
rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crDiscreteVal)
End If
End Select
Catch ex As Exception
Response.Write("<b><u>The report viewer has encountered an error:</u></b><br><br>")
Response.Write(ex.Message)
Response.Write("Stack Trace: " & vbCrLf & ex.StackTrace)
rcd.Close()
Finally
'do cleanup
End Try
Next
Ii am getting the error:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))Stack Trace: at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn) at _ViewRpt.DatabaseLogon_unmanagedRAS() in C:\inetpub\wwwroot\taser\report\ras\ViewRpt.aspx.vb:line 102
Is the crField item in the collection I am looping though (rcd.DataDefinition.ParameterFields) the same entity as your example "myParameterFieldDefinition."?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.