GUID of a custom SSRS report Published in Dynamics CRM 365 - reporting-services

I have a custom SSRS report published to MS Dynamics 365 that I am trying to call on a form button-click. I want to run the report for a selected record of an Entity. I am able to retrieve the EntityGuid run-time and pass it to the report.
How do I get the ReportGuid in order to pass it as an argument in the url ?
What is an entityType in the Url and where do I find the value of a custom entity?
Url looks like this -
var url = serverUrl + "/" + organizationName + "/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=" + rdlName + "&id={"+reportGuid+"}&records=" + entityGuid + "&recordstype=" + entityType;
window.open(url);

The XrmToolbox can help with both questions:
Using the FetchXML tester, this query will retrieve the names and GUID's of all the reports:
<fetch>
<entity name="report" >
<attribute name="name" />
<attribute name="reportid" />
</entity>
</fetch>
And the MetaData Browser shows each entity's ObjectTypeCode (a.k.a. EntityTypeCode or "etc").
And for the record, CRM provides a way to run a report from a form. After you configure the report to be available from the form, go to ellipsis and select Run Report:

Open Dynamics CRM -> Navigate to reports -> Find report you wand to get guid of -> select it and click "Edit" button in the Command Bar -> check url of window that popped up -> it should be something like https://yourorgname.crm.dynamics.com/CRMReports/reportproperty.aspx?id=%7b8484A9E3-3F8B-E611-80EE-C4346BAC897C%7d
Part after id= is your guid. In my case it is "8484A9E3-3F8B-E611-80EE-C4346BAC897C"
Good luck.

Related

SSRS - query parameter reference which does not exist in Parameters collection

I have a report that works. I add a new data set (report still work). I add parameters to the new dataset (report fails). The full error message is this:
The Value expression for the query parameter ':IP_START_DATE' contains
an error. The expression references the parameter 'paramStartDate',
which does not exist in the Parameters collection. Letters in the
names of parameters must use the correct case.
My problem is very similar to this one (SSRS 2008: error message saying my parameter doesn't exist but it clearly does?). But I have tried the suggestions there (Reorder report parameters, Copy the code to a new report, delete the ".Data" file, parameter casing is correct).
None of these work, I keep getting the error. Something that looks very odd to me is when I configure the Dataset Parameters Value to map to the Name, the Values are not in the correct order as defined in my Report Parameters section. Screenshot include below.
Does anyone have an answer as to why the drop down in my screenshot below is not in the correct order? And how to resolve this? I believe this could be the cause. Some things I have tried are included below. I have also verified all fields in the source database are in upper case, and my SQL dataset matches this.
Thanks,
Brian
See Below:
Screenshot of the mapping with wrong order
Screenshot of the XML tags for "ReportParameters"
XML code for "ReportParameters"
Steps I have taken to completely delete and re-add the parameters but they are still in the wrong order.
Remove/Add the parameters:
In the Code, DELETE the "" and "" nodes (found after "/ReportSections" and before "Code").
Remove all "" nodes.
View the report designer and verify report and query parameters are gone. Close the designer file. Open the designer file.
In the Code, ADD the "ReportParameters" and "ReportParametersLayout" nodes back in (between found between "/ReportSections" and "Code").
In the Report refresh your data sets. Then map the parameters.
Screenshot - Param Dropdown (wrong oder):
Screnshot - XML:
the XML:
<ReportParameters>
<ReportParameter Name="paramLocCode">
<DataType>String</DataType>
<Prompt>Location</Prompt>
<ValidValues>
<DataSetReference>
<DataSetName>listLocationData</DataSetName>
<ValueField>LOC_CODE</ValueField>
<LabelField>fxLabel</LabelField>
</DataSetReference>
</ValidValues>
</ReportParameter>
<ReportParameter Name="paramStartDate">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>=Format(Today(), "MMddyy")</Value>
</Values>
</DefaultValue>
<Prompt>Start Date "MMDDYY"</Prompt>
</ReportParameter>
<ReportParameter Name="paramEndDate">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>=Format(Today(), "MMddyy")</Value>
</Values>
</DefaultValue>
<Prompt>End Date "MMDDYY"</Prompt>
</ReportParameter>
</ReportParameters>
<ReportParametersLayout>
<GridLayoutDefinition>
<NumberOfColumns>2</NumberOfColumns>
<NumberOfRows>3</NumberOfRows>
<CellDefinitions>
<CellDefinition>
<ColumnIndex>0</ColumnIndex>
<RowIndex>0</RowIndex>
<ParameterName>paramLocCode</ParameterName>
</CellDefinition>
<CellDefinition>
<ColumnIndex>0</ColumnIndex>
<RowIndex>1</RowIndex>
<ParameterName>paramStartDate</ParameterName>
</CellDefinition>
<CellDefinition>
<ColumnIndex>1</ColumnIndex>
<RowIndex>1</RowIndex>
<ParameterName>paramEndDate</ParameterName>
</CellDefinition>
</CellDefinitions>
</GridLayoutDefinition>
</ReportParametersLayout>
SQL Dataset Query:
--listLocationData
-- DEFINE ip_start_date = '070120';
-- DEFINE ip_end_date = '070120';
SELECT DISTINCT
t1.LOC_CODE
, t2.LOC_DESCR
, t2.COMPANY
, t2.STATE_CODE
, t2.TYPE
FROM
VEHICLE_COST t1
JOIN VEHICLE_LOC t2
ON t1.LOC_CODE = t2.LOC_CODE
WHERE TO_CHAR(INVOICE_DATE,'MMDDYY') BETWEEN :IP_START_DATE AND :IP_END_DATE
Based on the additional information in your comment, this appears to be an issue with the parameter dependency. The start and end dates are used to generate location codes which are then populated in a drop-down and used for the subsequent dataset. If I'm understanding this correctly, the solution is to reorder the parameters.
In the Report Data section, under the Parameters folder, click on paramLocCode to select it.
Use the blue Down arrow at the top of the Report Data section to move it below the two date parameters.
Now the parameters will be referenced in order of their dependency on each other. The order of the datasets doesn't matter.

How can I set an expression for an external image when the file name is coming from a stored procedure column

My team and I are in the process of migrating from Crystal Reports to SQL Server Reporting Services. A handful of our reports involve what my team refer to as "dynamic external images". What this means is that in the report we would have this default blank image object, and then in the Graphic Location setting we would have the following function:
Trim({rpt_StoredProc;1.SignaturePath}) + Trim({rpt_StoredProc;1.SignatureId}) + ".jpg"
This way, we could pass through the directory path and the file name (minus the file extension) via the stored procedure.
I'm now trying to replicate this in SQL Server Reporting Services Report Builder and I'm running into a brick wall.
Your data relating to dynamic external images having been imported in SSRS should be accessible in a table using the data type varbinary(max). This can be accessed and utilised in an SSRS report either as a single field (ie in a header/title) or in matrix a field.
Both usages require you use the toolbox, (view and select toolbox) and left mouse click , drag "image" to your report, image source "database", use the field (select varbinary(max) field) , MIME type try "image/bmp" first, select the size to suit your needs.
and you should be good to go.
Best of luck.
I finally found the answer!
="file://" & First(Fields!SignaturePath.Value, "rpt_StoredProc") & "\" & First(Fields!SignatureId.Value, "rpt_StoredProc") & ".JPG"
I thought I had already tried this and that it didn't work, but I guess not.

Export stored procedure result set to Excel in SSMS

i'm using SSMS and attempting to export the results of a stored procedure to a new excel file. The SP accepts an int parameter but I cannot find a way to call it in the query.
Latest effort-
EXEC sp_makewebtask
#outputfile = 'C:\Users\me\Documents\testing.xls',
#query = **ExportAsExcel** N'#id' = 123
#colheaders =1,
#FixedFont=0,#lastupdated=0,#resultstitle='Testing details'
Running the stored procedure results in two tables of data, which I need on separate sheets. Can any of you advise a better way to go about this? It doesn't even need to be automated, I just need to get the correct data. The sp name is bolded above.
Thanks for your time,
H
I suggest you split your stored procedure into two procedures that each respectively return a separate table and have those called to different worksheets.
There are a variety of ways to return data to Excel using SQL
Here is a favourite of mine from code by Joshua (you don't have to use the parameters):
Select the Data tab on Excel's Ribbon, then within the Get Exernal Data group choose the "From other Sources" drop-down. Then Choose "From Microsoft Query"
Within "Choose Data Source" pop-up box, select your SQL Server, then hit OK.
Close the "Add Tables" popup if necessary.
Click on the "SQL" button, or choose View > SQL to open the SQL pop-up editor.
Enter the following syntax: {CALL myDatabaseName.dbo.myStoredProc (?, ?, ?)}
For example: {CALL northwind.dbo.spGetMaxCost (?, ?, ?)}
Be sure to include the squiggly braces around the call statement. Each Question Mark (?) indicates a parameter. If your stored procedure calls for more or less parameters, add or subtract question marks as needed.
Hit the OK button. A question box should pop-up saying "SQL Query can't be represented graphically, continue anyway?", just hit the OK button.
You will now be asked for sample parameters for each question mark you included above. Enter valid parameter values for the data you are querying.
Once you have entered the last parameter, you should get some results back in Microsoft Query. If they look good, close Microsoft Query.
You should now be looking at an "Import Data" pop-up. Click the Properties button, which will bring up the "Connection Properties" pop-up.
Select the Definition tab, then select the Parameters button. You should now see a "Parameters" pop-up, where you can connect the parameter to a specific cell.
Select Get the value from the following cell, and then connect to an appropriate cell in Excel that will hold your parameter, by clicking the little box with the arrow.
If you want the data to refresh every time you change the cell containing the parameter, check the box stating "Refresh automatically when cell value changes"
Continue as above for the other parameters. When finished, click OK, to return to the Connection Properties pop-up. Click OK to return to the Import Data pop-up, and click OK again.
You should now have some data straight from your stored procedure.
You will end up with connection information similar to:
Connection info
And, if you use parameters from sheet then, for my example,
This isn't a direct answer to your question, but it is possible using Excel VBA and connections to connect to a SQL Server Stored Procedure, feed it parameters, and return the SP result set in Excel. Check out my article Microsoft Excel & SQL Server: Self service BI to give users the data they want for an image and code-heavy demo.
Good luck.
There's too much detail there to post in a single SO question, otherwise I'd do that here.
I develop SSMSBoost add-in and we have implemented the functionality, that allows you to export data to excel in 3 ways (including creation of several worksheets in one file):
You can export all result grids in one operation to "open worksheet" file format, which excel understands and displays correctly. This file format supports multiple worksheets.
to use it: right-click the data grid in SSMS and select "Script grid data"-> "Excel" template->All Grids->ToDisk.
You can also look inside the generated files to understand how it works. You can then implement same functionality in your stored procedure if you want to stay independent of add-ins. Sample XML is also provided below. (2 excel sheets with 1 column name and 1 value)
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
</ExcelWorkbook>
<Styles>
<Style ss:ID="sH1"><Font ss:Bold="1"/></Style>
<Style ss:ID="sD1"><NumberFormat ss:Format="General Date"/></Style>
<Style ss:ID="sD2"><NumberFormat ss:Format="Short Date"/></Style>
<Style ss:ID="sD3"><NumberFormat ss:Format="Short Time"/></Style>
</Styles>
<Worksheet ss:Name="GridResults1">
<Table>
<Row>
<Cell ss:StyleID="sH1"><Data ss:Type="String">ColumnNameA</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
</Table>
</Worksheet>
<Worksheet ss:Name="GridResults2">
<Table>
<Row>
<Cell ss:StyleID="sH1"><Data ss:Type="String">ColumnNameB</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
You can also copy-paste data from SSMS Grid, right-clicking it and choosing "Copy selection as XML Spreadsheet (Excel)". Data will be copied preserving data types.
More advanced option is our "Post execution handlers" functionality. It allows you to run certain actions after query execution completes. You can schedule automatic export to excel file here as well.
Hope this helps, with, or without SSMSBoost ;)

MySQL Query - Search using wildcards at front and rear and an input parameter. Visual Studio 2012 - VB.NET

I am currently working on a POS system as a project for my studies. We are building the application in VB winforms using visual studio 2012.
I have the MySQL for Visual Studio installed and have a datasource/connection/dataset set up via the data sources panel in VS.
I am currently trying to make a TableAdapter query using the VS Query Builder which searches a product name however using the standard WHERE (ProductName = #inputParamName) you need a 100% match in #inputParamName for it to display the respective data.
I have tried using WHERE (ProductName LIKE '%' + #inputParamName + '%') however it gives me a MySQL error.
If anyone could help me out, it would be greatly appreciated.
Thanks
OK, I edited my answer to use a different approach. You can do the following. When you create a SqlDataSource in VS, it adds the SelectCommand in the aspx. Set the command to nothing and add a SelectParameter, like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="param1" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Now in the code behind, you can change the SelectCommand and pass it a param like this:
{
// Run this on a click or selected index change
string m_param = "2012"; //this would be something like Textbox1.Text
this.SqlDataSource1.SelectParameters[0].DefaultValue = m_param;
this.SqlDataSource1.SelectCommand = "SELECT ID, FILENAME FROM drmc.checksum WHERE FILENAME LIKE '%" + this.SqlDataSource1.SelectParameters[0].DefaultValue + "%'";
}
You will need to test the "Textbox1.Text" value against SQL Injection. Regex is good for this.

How to get the identity of the user who ran a report?

When executing a report in MSCRM 2011, you have two options for the data sources : either SQL or Fetch.
In SSRS execution logs, the user who ran the report is always the service account.
When using fetch, in the report execution log, there is a parameter CRM_FullName containing the full name of the user who ran the report.
When using SQL source, there is no CRM_FullName parameter. How can I know who ran the report? There must be a way to know, since the Filtered views know who I am.
There is actually no way to find this information. When you create a report for MSCRM, you use a connector called "MSCRM Data Connector". This can be seen in the AdditionnalInfo column of the ExecutionLogs3 view on the SSRS instance. When using this connector and trying to show a report, you will get prompted for username and password. That's where things get interesting.
The report is not actually expecting a username/password! In fact, it expects to receive the systemuserid (guid) as username and the organizationid (guid) as password. It then search in the MSCRM_CONFIG database for the organization database settings. Then, it goes into the organization database and simply do a set context_info SYSTEMUSERID. Finally, the filteredviews are calling a function named '[dbo].[fn_FindUserGuid]' that retrieves the context_info. That is how the filtered views are properly working, while connected as the service account.
As you might have expected, we can't know the user who ran the report because the username and password prompts in SSRS are never logged anywhere (for security matters, perhaps).
The best option that I have found to log who ran a report is to actually create a stored procedure that will make a select statement on the filtered views (or any tables, as it is) and then log into a separate table the statement, the procedure parameters and the context_info(). Then, in SSRS I call that function instead of going to the filtered views directly.
Answer edited to include the getting the user fullname if sql source is used.
Register a parameter, UserID, with default value as
=User!UserID
Use the following query in your dataset
SELECT DomainName, FullName
FROM SystemUserBase
WHERE (DomainName = #UserID)
Then use
=Fields!FullName.Value
in your report.
In the CRM the user data is stored in the SystemUserBase table, and the DomainName column is the actual Domain\Username stored in User!UserID of the report.
If you prefer using views, use FilteredSystemUser view instead of SystemUserBase table.
For fetchxml try the following:
The operator operator='eq-userid' means equal to the current user.
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
<entity name='team'>
<attribute name='name' />
<attribute name='businessunitid' />
<attribute name='teamid' />
<order attribute='name' descending='false' />
<link-entity name='teammembership' from='teamid' to='teamid' visible='false' intersect='true'>
<link-entity name='systemuser' from='systemuserid' to='systemuserid' alias='user'>
<attribute name='fullname' />
<attribute name='systemuserid'/>
<filter type='and'>
<condition attribute='systemuserid' operator='eq-userid' />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
Then in your report you can use the following code in an expression to get the users fullname
=First(Fields!user_fullname.Value, "GetUserData")
where the dataset is called GetUserData
Will the user login name suffice? i.e. can you just use something like
="Generated by " & User!UserID ?