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

No option to update data set #42

Open
ghost opened this issue Apr 4, 2018 · 3 comments
Open

No option to update data set #42

ghost opened this issue Apr 4, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 4, 2018

On data sources, there is the option to either update the data source or include the data source. Update will update the reference, while include will actually upload the data source.

Can we do this for datasets also? Right now, there is only the option to upload the dataset. It won't update the reference to the shared dataset like it does for datasources

@mjcarrabine
Copy link

I am running into the same issue.

I normally put all the shared datasets into a separate folder than the reports so this feature is required.

@mjcarrabine
Copy link

When a report is uploaded, and the datasource doesn't exist at the expected location, it throws a warning, and the extension is able to update it's reference by looking up the datasource by name.

When a dataset is uploaded, and the datasource doesn't exist at the expected location, it throws a warning. However, the name is always DataSetDataSource so I had to get the name from the xml of the dataset.

The code below shows two ways of updating the datasource reference on the dataset.

  • The first is using SetItemDataSources that we use on Reports. However, the documentation doesn't say this method should work on datasets, only reports and models.
  • The second method (commented out) uses SetItemReferences which the documentation says will work on datasets.

I hope this helps!

##########################################################
#		            Uploading datasets                   #
##########################################################

	$rsdFiles = @(Get-ChildItem $DataSetLocalPath);
	$rsdFileCount = $rsdFiles.Length;
	if($IncludeDataSet -eq $true){
		Write-Host "Uploading $rsdFileCount Dataset files";
		$rsdFiles | ForEach-Object {
			$datasetName = $_.FullName; 
			$datasetFileName = [System.IO.Path]::GetFileNameWithoutExtension($datasetName);
			Write-Host "Uploading dataset $datasetName to $DataSetRootPath...";
			Verbose-WriteLine "Reading $datasetName file...";
			[xml]$rsd = Get-Content -Path $datasetName;
			$byteRsd = Get-Content -Encoding Byte -Path $datasetName
			$warnings = $null;
			try{
				$dataset = $ssrs.CreateCatalogItem(
					"DataSet",
					$datasetFileName,
					$DataSetRootPath,
					$true,
					$byteRsd,
					$null,
					[ref]$warnings
				);
				
				#If any warning was logged during upload, log them to the console
				if($warnings -ne $null){
					Write-Warning "One or more warnings occured during upload:";
					$warningSb = New-Object System.Text.StringBuilder;
					$warnings | ForEach-Object{
						$txtWarning = $_.Message;
						$warningSb.AppendLine("`t- {$txtWarning}");
					}
					Write-Warning $warningSb.ToString();
				}

				$dataSetDataSourceReference = $rsd.SharedDataSet.DataSet.Query.DataSourceReference

				if($UpdateDataSource -eq $true){ #Update the datasources
					Write-Host "Updating the DataSources of the dataset $datasetFileName...";
			
					$serverDataSources = $ssrs.ListChildren($DataSourceRootPath, $true) | Where {$_.TypeName -eq "DataSource"};
					
					# Using Get/SetDataSources
					$neededDataSources2 = $ssrs.GetItemDataSources($DataSetRootPath + "/" + $datasetFileName);
					$neededDataSources2 | ForEach-Object{
						$reportDataSourceName = $_.Name;
							
						Foreach($serverDataSource in $serverDataSources){
							if([System.String]::Compare($serverDataSource.Name.Trim(),$dataSetDataSourceReference, $true) -eq 0){ # The Name of the neededDataSource is always DataSetDataSource so we need to use $dataSetDatasourceReference here
								$dataSourcePathNew = $serverDataSource.Path;
						
								Write-Host "Updating DataSource '$reportDataSourceName' to path '$dataSourcePathNew'..." -NoNewline;                        									

								$dataSourceReferenceNew = New-Object("$type.DataSourceReference");
								$dataSourceReferenceNew.Reference = $dataSourcePathNew;

								$dataSourceNew = New-Object ("$type.DataSource");
								$dataSourceNew.Name = "DataSetDataSource";
								$dataSourceNew.Item = $dataSourceReferenceNew;
									
								$ssrs.SetItemDataSources($DataSetRootPath + "/" + $datasetFileName, $dataSourceNew);

								Write-Host "Done!";
								break;
							}
						}
					}

                                        #http://bboydaisuke.blogspot.com/2010/08/how-to-set-shared-datasource-reference.html?m=1
					## Using Get/SetItemReferences
					#$neededDataSources = $ssrs.GetItemReferences($DataSetRootPath + "/" + $datasetFileName, "DataSet");
					#$neededDataSources | ForEach-Object{
					#	$reportDataSourceName = $_.Name;					
							
					#	Foreach($serverDataSource in $serverDataSources){
					#		if([System.String]::Compare($serverDataSource.Name.Trim(),$dataSetDataSourceReference, $true) -eq 0){ # The Name of the neededDataSource is always DataSetDataSource so we need to use $dataSetDatasourceReference here
					#			$dataSourcePathNew = $serverDataSource.Path;
						
					#			Write-Host "Updating DataSource '$reportDataSourceName' to path '$dataSourcePathNew'..." -NoNewline;                        									

					#			$dataSourceReferenceNew = New-Object("$type.ItemReference");
					#			$dataSourceReferenceNew.Name = "DataSetDataSource";
					#			$dataSourceReferenceNew.Reference = $dataSourcePathNew;

					#			$ssrs.SetItemReferences($DataSetRootPath + "/" + $datasetFileName, $dataSourceReferenceNew);

					#			Write-Host "Done!";
					#			break;
					#		}
					#	}
					#}
					
				}		

			}catch [System.Exception]{
				Write-Error $_.Exception.Message;
				#Terminate script
				exit -1;
			}
		}
	}

@anton-kirschhock
Copy link
Contributor

Ill look into this and keep you posted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants