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

New-RsSubscription does not accept -Parameters argument (and sets it to null) #97

Closed
jzabroski opened this issue Nov 1, 2017 · 14 comments · Fixed by #186
Closed

New-RsSubscription does not accept -Parameters argument (and sets it to null) #97

jzabroski opened this issue Nov 1, 2017 · 14 comments · Fixed by #186

Comments

@jzabroski
Copy link
Contributor

Do you want to request a feature or report a bug?
feature

What is the current behavior?
$Parameters is hardcoded to null and there is no API hook exposed to override this hardcoded behavior. See: https://github.com/Microsoft/ReportingServicesTools/blob/master/ReportingServicesTools/Functions/CatalogItems/New-RsSubscription.ps1#L205

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
I don't think I really need to explain this.

What is the expected behavior?
Feature parity with CreateSubscription SSRS WSDL endpoint.

Which versions of Powershell and which OS are affected by this issue? Did this work in previous versions of our scripts?

PS C:\> $PSVersionTable

Name                           Value                                                                                                                                                                                                 
----                           -----                                                                                                                                                                                                 
PSVersion                      5.1.15063.483                                                                                                                                                                                         
PSEdition                      Desktop                                                                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                               
BuildVersion                   10.0.15063.483                                                                                                                                                                                        
CLRVersion                     4.0.30319.42000                                                                                                                                                                                       
WSManStackVersion              3.0                                                                                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                   
SerializationVersion           1.1.0.1                                                                                                                                                                                               
@jzabroski
Copy link
Contributor Author

jzabroski commented Nov 1, 2017

I'm coding a solution to this now. I will use [hashtable] $Parameters as the new argument to New-RsSubscription

I suggest this be a breaking change to the current New-RsSubscription interface, and that once I submit my patch, the overall module get a bump to 0.0.3.x (I'm really unclear on what it means for a project to have 0 for major and minor versions... please consider using semver - semantic versioning scheme popular among Web developers.)

@jzabroski
Copy link
Contributor Author

So, the drawback to [hashtable] $Parameters is that, technically, $Parameters should support Label as well as Name-Value pair elements. I'm not aware of anyone ever actually using that feature, so I'll continue down the [hashtable] path and consider the Label feature over-engineering.

@jzabroski
Copy link
Contributor Author

Actually, the easiest thing to do is create a new function, New-RsSubscriptionParametersXml, similar to New-RsScheduleXml, which will allow us not to expose the full namespace of the SSRS WSDL types and yet keep the overall integrity of the API together. Plus, most people will probably want to use something like XML to manage these externally, anyway.

@jzabroski
Copy link
Contributor Author

I've got this mostly working, but can't find documentation on MSDN for how to say "This report uses default parameters" or "This report uses null valued parameters". I spied the SSRS Reports portal's Rest calls, and they pass an empty list via [] json in both cases. It seems like the SOAP API does things differently, though.

@wgshef
Copy link

wgshef commented Nov 14, 2017

This is the error message that I'm receiving when trying to add a report subscription for a report that needs some parameters set:

Exception occurred while creating subscription! Exception calling "CreateSubscription" with "6" argument(s):
"System.Web.Services.Protocols.SoapException: This report requires a default or user-defined value for the report
parameter 'DeviceID'. To run or subscribe to this report, you must provide a parameter value. --->
Microsoft.ReportingServices.Diagnostics.Utilities.ReportParameterValueNotSetException: This report requires a default
or user-defined value for the report parameter 'DeviceID'. To run or subscribe to this report, you must provide a
parameter value.
at Microsoft.ReportingServices.Library.ReportingService2005Impl.CreateSubscription(String Report, ExtensionSettings
ExtensionSettings, Boolean isDataDriven, DataRetrievalPlan DataRetrievalPlan, String Description, String EventType,
String MatchData, ParameterValueOrFieldReference[] Parameters, Guid batchId, String& SubscriptionID)
at Microsoft.ReportingServices.Library.ReportingService2005Impl.CreateSubscription(String Report, ExtensionSettings
ExtensionSettings, Boolean isDataDriven, DataRetrievalPlan DataRetrievalPlan, String Description, String EventType,
String MatchData, ParameterValueOrFieldReference[] Parameters, String& SubscriptionID)
at Microsoft.ReportingServices.WebServer.ReportingService2010.CreateSubscription(String ItemPath, ExtensionSettings
ExtensionSettings, String Description, String EventType, String MatchData, ParameterValue[] Parameters, String&
SubscriptionID)"

@jzabroski
Copy link
Contributor Author

I have this working in my local fork of the project and need to commit back upstream to avoid losing my changes. The big gotcha is if you export reports with parameters and try to import them back, things get crazy because of how the SSRS team handles default parameters where the default is a null. If someone at Microsoft were to explain this to me, I could probably write a robust integration.

@jzabroski
Copy link
Contributor Author

jzabroski commented Feb 26, 2018

I have to update my repository to 0.0.4.6 to integrate my change to make sure it works in the latest release of ReportingServicesTools. Here is a snippet of the changes - this should replace $ReportParameters = $Null at line 300:

            if ($Parameters -ne $null)
            {
                $parametersCopy = @{};
                # First, remove null-valued keys
                foreach ($key in $Parameters.Keys)
                {
                    if ($Parameters[$key] -ne $null)
                    {
                        $parametersCopy.Add($key, $Parameters[$key]);
                    }
                }

                $Parameters = $parametersCopy;

                if ($Parameters.Count -ne 0)
                {
                    $ParameterValues = New-Object "$Namespace.ParameterValue[]" $Parameters.Count

                    $i = 0;
                    foreach ($key in $Parameters.Keys)
                    {
                        Write-Output "Indexing into $i" | Out-Host
                        $tmpParameter = New-Object "$Namespace.ParameterValue"
                        $tmpParameter.Name = $key;
                        $tmpValue = $Parameters[$key]
                        if ([string]::IsNullOrWhiteSpace($tmpValue))
                        {
                            continue;
                            <#
                            $tmpName = $tmpParameter.Name;
                            Write-Output "$tmpName 's value is null" | Out-Host
                            $tmpParameter.Value = $null;
                            #>
                        
                        }
                        else
                        {
                            $tmpParameter.Value = $tmpValue # Default value or value provided for the report parameter 'date' is not a valid value.
                        }
                        Write-Output $tmpParameter | Out-Host; 
                        $ParameterValues[$i] = $tmpParameter
                        $i++;
                    }

                }
                else
                {
                    $ParameterValues = $null;
                }
            }
            else
            {
                $ParameterValues = $null
            }

Also, the signature should now say:

        .PARAMETER Parameters
            A hash that contains a set of parameters for the subscribed item.
        [Parameter(Mandatory=$True)]
        [AllowNull()]
        [hashtable]
        $Parameters

@jzabroski
Copy link
Contributor Author

@jtarquino Is there a better way to code this? This is how I have it working in my production environment, which is a fork of ReportingServicesTools 0.0.2.9. The reason it's so verbose is because of the apparent stupid way SSRS API treats nulls/empty values. It looks like the behavior broke at some point from 2005 to 2016 releases, most likely between 2008 R2 and 2012 releases.

@jzabroski
Copy link
Contributor Author

@jtarquino - Looking for some direction and then I can submit the patch.

@jtarquino
Copy link
Member

I think your approach is feasible, I would just change the Write-Output by Write-Verbose and avoid the continue in the loop, also probably would extract that logic into a function and add testing

@jzabroski
Copy link
Contributor Author

I am upgrading from 0.0.2.9 this week and plan to finally submit a patch for this to the 0.0.4.7 code.

@jzabroski
Copy link
Contributor Author

@jtarquino MERGED... Tried to keep it as simple as possible but SQL Server 2012+ is very finicky . It works on my side upgrading from 2008 to 2016.

@jzabroski
Copy link
Contributor Author

@wgshef FYI

@jusefb
Copy link

jusefb commented Dec 7, 2020

I have had to use this last week, one problem I found is that the Hash approach does not allow to use multivalue parameters

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

Successfully merging a pull request may close this issue.

4 participants