Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to retrieve the parameters for a given ssrs report? #25

Closed
faridjame opened this issue Sep 7, 2016 · 7 comments
Closed

Comments

@faridjame
Copy link

Is it possible to retrieve the required parameters for a given ssrs report?

@rb-cohen
Copy link
Member

rb-cohen commented Sep 8, 2016

If you call loadReport() you should get back lots of information on the report, including the parameters. Each parameter should have a required flag on it.

Something like this:

<?php
require(__DIR__ . '/../vendor/autoload.php');

$options = array(
    'username' => 'testing',
    'password' => 'password'
);

$ssrs = new \SSRS\Report('http://localhost/reportserver/', $options);
$result = $ssrs->loadReport('/Reports/Reference_Report');

$parameters = $result->getReportParameters();

@oranges13
Copy link

How do you retrieve conditional parameters? For example: based on the parameter chosen in one field, it updates the available params in another field. I'd prefer to default this value if I can before loading the list of parameters the first time.

Is this possible?

@rb-cohen
Copy link
Member

rb-cohen commented Dec 8, 2017

IIRC you have to update the parameters, then grab the 'updated' conditional parameters from SSRS. I don't think you can get a list of everything right off the bat.

It has been a while, but we did something like this, where $knownValues are the default values or the previously submitted values:

$executionParameters = new SSRS_Object_ExecutionParameters($knownValues);
$newExecutionInfo = $ssrs->setExecutionParameters($executionParameters);

$ssrs->setSessionId($newExecutionInfo->ExecutionID);
$newParameters = $newExecutionInfo->getReportParameters();

// here we had a form generator, eventually populating a HTML form based off the available parameters and values
$formGenerator->generate($newParameters);

$output = $ssrs->render('HTML4.0'); // PDF | XML | CSV

@oranges13
Copy link

Thanks for the response. Unfortunately this code doesn't work. Here's the full snippet of what I tried:

This code fails with "Session ID not set"

// You need to connect to the server and load your report
$ssrs = new \SSRS\Report('http://myserver/ReportServer', array('username' => 'user', 'password' => 'password'));
$report = $ssrs->loadReport('/Folder/Report');

// Add execution parameters from submission
$execution_params = new \SSRS\Object\ExecutionParameters($requestedFilters);
$new_report = $ssrs->setExecutionParameters($execution_params);

$ssrs->setSessionId($new_report->ExecutionID);

// Params to send to the form view
$available_params = $new_report->getReportParameters();

Your other examples in the wiki indicate that the session id has to be set in the same statement as the setExecutionParameters but if I use that session ID, the parameters I get at the end are just the defaults, not reflective of the data I sent for the report.

// If I instead use the previous session ID:
$new_report = $ssrs->setSessionId($report->ExecutionID)->setExecutionParameters($execution_params);

// Do not reflect the values submitted
$available_params = $new_report->getReportParameters();

// Just for giggles and grins
$new_report->executionInfo->Parameters; // this is null

Here's an example -- you can see value is null even though I am sending a value and the report executes as if a value has been sent.

array:9 [▼
  0 => ReportParameter {#1181 ▼
    +name: "parForecastDate"
    +value: null
    +data: array:13 [▶]
  }
  1 => ReportParameter {#1555 ▼
    +name: "parMonths"
    +value: null
    +data: array:13 [▶]
  }
  2 => ReportParameter {#1561 ▼
    +name: "parType"
    +value: null
    +data: array:13 [▶]
  }
]

The issue with this is that sending these available parameters to our form builder, and one of them has no options available because it's not showing a value for a dependency.

At this point I'm stumped and I might have to build the form filters manually and just send the data to get the report.

@rb-cohen
Copy link
Member

rb-cohen commented Dec 8, 2017

If the execution ID isn't updated any subsequent requests won't reflect your submission. The execution ID from SSRS is like a state marker.

In your example, where you keep the old session ID, you'll get back the state before you submitted anything.

Unfortunately I don't have access to an SSRS server at the moment to run some tests, but the code should work. Here is a fuller example from the snippet I sent, you'll see we keep updating the session ID to the latest execution ID:

$ssrs = new SSRS_Report('http://testing/reportserver/', $options);
$executionInfo = $ssrs->loadReport($reportName);
$ssrs->setSessionId($executionInfo->ExecutionID);

$executionParameters = new SSRS_Object_ExecutionParameters($knownValues);
$newExecutionInfo = $ssrs->setExecutionParameters($executionParameters);

$ssrs->setSessionId($newExecutionInfo->ExecutionID);
$newParameters = $newExecutionInfo->getReportParameters();

// here we had a form generator, eventually populating a HTML form based off the available parameters and values
$formGenerator->generate($newParameters);

$output = $ssrs->render('HTML4.0'); // PDF | XML | CSV

Hopefully that helps a bit? Sounds like its almost there...

@oranges13
Copy link

oranges13 commented Dec 8, 2017 via email

@rb-cohen
Copy link
Member

rb-cohen commented Dec 8, 2017

Phew, good to hear! :)

@rb-cohen rb-cohen closed this as completed Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants