Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing multiple values to a parameter using RAS

Status
Not open for further replies.

D1000

Technical User
Aug 16, 2002
46
0
0
US
I am having trouble passing multiple values to a paremeter. We have a Crystal report with an EmployeeID parameter that is set up to accept multiple values (4,5,...).

I can call the parameter with a single discrete value and everything works fine, as in:

~~~~~~~~~~~~~~~~~~~~
Set Values = CreateObject("crystalReports.Values")

Set DiscreteValue = CreateObject ("CrystalReports.ParameterFieldDiscreteValue")

DiscreteValue.Value = ParamValue

Values.Add DiscreteValue

Session("oClientDoc").DataDefController.ParameterFieldController.SetCurrentValues "", "EmployeeID, "4"
~~~~~~~~~~~~~~~~~~~~

However, I have been unable to find any documentation that explains how to pass more than one value. I have tried various mechanisms and have been unable to get it to work. Is there any other property that will allow us to pass multiple values?

Session("oClientDoc").DataDefController.ParameterFieldController.SetCurrentValues "", "EmployeeID, "4,5
 
In a code sample I've seen pipes | separating the values and those seem to work, but I wouldn't get hopes up.
 
Hi,
This code should show you the method to add multiple params..These are hard coded, but passing them should not be a problem:

Code:
<%

option explicit
'===================================================================
' AUTHOR - SG, KA, modified by RLang April 23rd 2004
' CREATED - March 31, 2004
' PURPOSE - This sample ASP application demonstrates how to view a 
'           report on demand using the Crystal Enterprise 10 COM SDK.
' DESCRIPTION
'	- Define CE Logon Variables
'   - Create the Enterprise Session Manager and iStore objects
'   - Query the CMS for a report to view
'	- Create viewer object and view report
'==================================================================

 Sub SetCurrentValues(Report, ParameterName, newValue)
	dim ParameterFieldIndex
	Dim ParameterToChange
	Dim Value
	
	ParameterFieldIndex = Report.DataDefinition.ParameterFields.Find(ParameterName, 0)
	set ParameterToChange   = Report.DataDefinition.ParameterFields.Item(ParameterFieldIndex)
	
	'ParameterToChange.CurrentValues.RemoveAll
	
	Set Value = Server.CreateObject ("CrystalReports.ParameterFieldDiscreteValue")
	
	Value.Value = newValue
	
	ParameterToChange.CurrentValues.add value
End Sub

'Declare the CMS Logon Variables
Dim CMS
Dim Username
Dim Password
Dim Authtype

'Set CMS logon credentials - change these to match your particular CE environment
CMS = "ven-win2ksjcr10"
Username = "administrator"
Password = ""  
Authtype = "secEnterprise"

dim reportID
dim ReportUser
dim ReportPw

ReportID   = Request.QueryString ("ReportID")
ReportUser = Session("ReportUser")
ReportPW   = Session("ReportPW")

'Response.Write "USER = " & ReportUser

'Declare variables for Enterprise Session
Dim oEnterpriseSessionMgr
Dim ceSession
Dim iStore

'Load the Enterprise Session Manager
Set oEnterpriseSessionMgr = Server.CreateObject("CrystalEnterprise.SessionMgr")

'Logon to the CMS and create iStore object
Set ceSession = oEnterpriseSessionMgr.Logon(Username, Password, CMS, Authtype)
Set iStore = ceSession.Service("","InfoStore")

'Declare InfoObject Variable
'Dim Reports
'Dim Report

'Query CMS for the report to view
Dim Reports
Dim Report

Set Reports = iStore.Query("SELECT SI_ID, SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID=" + ReportID)
set Report = Reports.Item(1)

'Declare the Report App Factory and Report Document Objects
Dim rptAppFactory
Dim reportDocument

'Create the Report App Factory and Report Document Objects
Set rptAppFactory = iStore.EnterpriseSession.Service("","RASReportFactory")
Set reportDocument = rptAppFactory.OpenDocument(Report)

'logon to the report.
reportDocument.DatabaseController.Logon ReportUser, ReportPW

'pass parameters to the report.
'
				'the report,  name of the parameter, value to give the parameter
SetCurrentValues(reportDocument, "StringParameter","myStringValue")
SetCurrentValues(reportDocument, "NumberParameter","9")
SetCurrentValues(reportDocument, "DateParameter","12/25/2003")
 
'Declare the viewer object variable
Dim Viewer

'Create a viewer object and view the report
Set Viewer = CreateObject("CrystalReports.CrystalReportViewer")
With Viewer
  .reportSource = reportDocument.ReportSource
  .EnterpriseLogon = iStore.EnterpriseSession
  .HasPrintButton = true
  .PrintMode = 1 ' activeXprinting
  .IsOwnPage = true
  .URI = "?ReportID="+ReportID
End With

'Error handle
on error resume next
'Viewer.ProcessHTTPRequest Request, Response, Session

if err.number <> 0 then
  response.write "Failed to view report" & "</BR>"
  response.write "error number: " & err.number & "</BR>"
  response.write "error description: " & err.description
end if
%>
[/color blue]

Hope it helps...

[profile]
 
Turkbear -

Does your code demonstrate addition of multiple values to a single parameter, or addition of single values to multiple parameters?

I have not used RAS, but from my experience with ePortfolio and an ignorant* reading of the code, I picked out the statement

ParameterToChange.CurrentValues.add value

in the SetCurrentValues function. I believe D1000 would want to execute this statement once for each parameter value, but not the entire function. The function does a RemoveAll, which would not be done between values.

Just a guess.

- Mike

* Referring to my own ignorance in this area.
 
Hi,
The "remove all" is commented out..

By setting up a loop for the multiple values for the same parameter, this 'call' would add values ( if the parameter is correctly defined as allowing multiple values..)
This code demonstrates the use of a passed array containing the multiple values for a parameter:

Code:
<%
'===================================================================
' AUTHOR - SG, KA
' CREATED - March 31, 2004
'MODIFIED by Turkbear 6/1/2004 to utilize passed arrays 
' PURPOSE - This sample ASP application demonstrates how to view 
'           on demand a report with multiple value parameter 
'           using the Crystal Enterprise 10 COM SDK.s
' DESCRIPTION
'	- Define CE Logon Variables
'   - Create the Enterprise Session Manager and iStore objects
'   - Query the CMS for a report to view
'	- Create and pass parameter for the report
'	- Create the viewer object and view the report
'==================================================================

'Declare the CMS Logon Variables
Dim CMS
Dim Username
Dim Password
Dim Authtype

'Set CMS logon credentials - change these to match your particular CE environment
CMS = session("APS")
Username = session("User")
Password = session("Pass")
Authtype = session("Auth")

'Declare variables for Enterprise Session
Dim oEnterpriseSessionMgr
Dim ceSession
Dim iStore
'Get the values
Rid = Request.QueryString("ReportID")
NbrParams = Request.QueryString("NumParens")
If NbrParams > 0 then
ValStr   = Request.QueryString ("Pvals")
NameStr = Request.QueryString ("Pnames")
arrVals = Split(ValStr,";")
arrNames = Split(NameStr,",")
End If


'Load the Enterprise Session Manager

Set oEnterpriseSessionMgr = Server.CreateObject("CrystalEnterprise.SessionMgr")

'Logon to the CMS and create iStore object
Set ceSession = oEnterpriseSessionMgr.Logon(Username, Password, CMS, Authtype)
Set iStore = ceSession.Service("","InfoStore")




'Query the CMS for the report you wish to view
query = "Select SI_ID from CI_InfoObjects Where SI_ProgID = 'CrystalEnterprise.Report' and SI_ID=" & Rid
Set queryResult = iStore.Query(query)
Set rptAppFactory = iStore.EnterpriseSession.Service("","RASReportService")
Set reportDocument = rptAppFactory.OpenDocument(queryResult.Item(1))
'************** Start of code snippet **********************
 
Sub PassParameter(strParamName, ParamValue)
 
    'Determine the index position of the parameter in the report
    ParamIndex = reportDocument.DataDefinition.ParameterFields.Find(strParamName,0)
 
    'Get parameter in the report at the position ParamIndex
    Set objParam = reportDocument.DataDefinition.ParameterFields.Item(ParamIndex)
 
    'Clone the parameter object so we can modify it
    Set objNewParam = objParam.Clone
 
    'Add parameter field value to this object
    objNewParam.CurrentValues.Add ParamValue
 
    'Insert the modified parameter back into the report
   
    reportDocument.DataDefController.ParameterFieldController.Modify ParamIndex, objNewParam
        
End Sub
'*************************** End of code from CE tech support*****************************************************



If NbrParams > 0 then ' only need to do this is parameters actually are needed
                       ' Use the passed arrays to determine Parameter Name and Values
for n = 0 to NbrParams
   arrPvals = Split(arrVals(n),",")
         for each val in arrPvals  ' assign the value to the parameter
                  PassParameter  arrNames(n)   , Trim(val)
        Next  '   Next val
 Next     ' Next N 
End If   ' # of Params

'Declare the viewer object variable
Dim Viewer

'Create a viewer object and view the report
Set Viewer = CreateObject("CrystalReports.CrystalReportInteractiveViewer")
With Viewer
  .reportSource = reportDocument.ReportSource
  ' Adds a Advanced Search Wizard button to the toolbar.
  .HasBooleanSearchButton = True
  ' Enables the Advanced Search Wizard.
  .EnableBooleanSearch = True
  .HasCrystalLogo = False
  .IsDisplayGroupTree = False
  .HasPrintButton = true
  .PrintMode = 1 ' activeX Printing
  .IsOwnPage = true
End With

set session("viewer") = viewer

Response.Redirect("viewprint.asp")

 

%>

In all cases, these are only examples of a methodology, and will, of course, need modification for actual use by anyone else.

[profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top