Skip to Content
0

Report Optional prompt not working again.

May 09 at 09:09 PM

34

avatar image

Several years ago in a previous version of Crystal Reports the optional prompt did not work properly and I had to set values to zero and test for that rather than using the HasValue function. I recently upgraded to v22 and now find all of my reports with parameters that support a list of values are now prompting the user for values, even when the list has values in it.

This routine has worked for several years and is used to set a list of values into parameters:

    Public Sub ApplyIDS()
        Dim pdv As ParameterDiscreteValue
        With _parameter.CurrentValues
            .Clear()
            Select Case _IDs.Count
                Case 0
                    If ZeroEmptyParameter Then
                        Report.SetParameterValue(_parameter.ParameterFieldName, 0)
                    Else
                        .IsNoValue = True
                    End If
                Case 1
                    If _parameter.ParameterType = CrystalDecisions.Shared.ParameterType.StoreProcedureParameter Then
                        Report.SetParameterValue(_parameter.ParameterFieldName, _IDs(0))
                    ElseIf _parameter.ParameterType = CrystalDecisions.Shared.ParameterType.ReportParameter Then
                        SetCrystalParam(Me.Report, _parameter.ParameterFieldName, _IDs(0))
                    End If
                Case Else
                    For Each paramValue As Int32 In _IDs
                        pdv = .AddValue(paramValue)
                    Next
            End Select
        End With
    End Sub

The Case Else is the one being executed. After this exits I can see that the parameter in question has a list of current values. The report in question uses the following code to check the parameter:

((({?MICID}=0) and hasvalue({?MICShareID}) and {vwMICSharesForRedemption.MSID}={?MICShareID})
or ({vwMICSharesForRedemption.MICID}={?MICID})
    and ({vwMICSharesForRedemption.TransferCertificateRequired} = true
         or {vwMICSharesForRedemption.RedemptionCertificateRequired} = true))

In this report the MICID is usually zero and a list of MICShareIDs is set by the above code. As of the most recent version, all of the reports which use this technique are now ignoring the list of values that have been set and are prompting for lists of values. What changed between v13 and v22?

I am a little desperate as I need to get a release out and I was going to upgrade all of the users to the most recent v22 runtime. I cannot do so if all of the reports are going to prompt for parameters.

Thanks, Neil

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Neil Johnson May 10 at 02:49 AM
0

Don, I found a work-around, although I don't know why it works. Basically the 'else' code gets replaced with a new function, based on a routine that I think you had previously written and that I have adapted:

                    SetCrystalParamList(Of Integer)(Me.Report, _parameter.ParameterFieldName, _IDs)

The new function is this:

    Friend Sub SetCrystalParamList(Of E)(rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument, parameterName As String, listOfValues As IEnumerable(Of E))
        Dim ParCount As Integer = rpt.DataDefinition.ParameterFields.Count
        Dim crDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue
        For Each crParamField As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition In rpt.DataDefinition.ParameterFields
            If crParamField.Name.ToLower() = parameterName.ToLower() OrElse "@" + crParamField.Name.ToLower() = parameterName.ToLower() Then
                Try
                    Dim myparameterValues As New CrystalDecisions.Shared.ParameterValues()
                    'myparameterValues.IndexOf(crParamField.Name)
                    For Each value As E In listOfValues
                        crDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()
                        crDiscreteValue.Value = value
                        myparameterValues.Add(crDiscreteValue)
                    Next
                    crParamField.ApplyCurrentValues(myparameterValues)
                    Return
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                    Return
                End Try
            End If
        Next
    End Sub
 

This successfully sets the value list and prevents prompting. Why this works and parameter.AddValue() does not, I have no clue.

Thanks, Neil

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
May 09 at 09:30 PM
0

Hi Neil,

Yes Parameter flows have changed again. I wrote a test app that has a drop down list to get parameters and their values etc.:

how-to-parameters-in-crystal-reports-for-visual-studio-net

With some changes see if this works for you to set values.

Also, it is possible that the database connection is not working which would cause the parameters to fail, based on the type of course.

You must set the parameter values before connecting to a SP and you must set DB connection before getting a dynamic list of values.

Don

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Don, I looked at your example, but it does not seem to deal with a range of values. The code shown above has worked for at least the last 4-5 years before I upgraded from V13 to V22. Setting a single value works fine - the code in case 1 kicks in and a single value is assigned to the parameter - no prompting occurs. When multiple values are added, they are not recognized and a prompt is shown. This code used to work, prior to the new version.

0