Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Using macros in report parameter defaults View modes: 
User avatar
Member
Member
lancetek - 10/20/2011 10:20:29 AM
   
Using macros in report parameter defaults
For most of the Kentico reports I'd like to be able to pre-populate the FromDate and ToDate with dynamic values; Most of the reports I'd like to run for a month, so a FromDate 30 days ago and a ToDate of today would be great.

Reports > parameters > FromDate > default value - I've tried a few macros in here, but none of them seem to work

Thanks,
Lance

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/21/2011 12:05:14 AM
   
RE:Using macros in report parameter defaults
Hi,

Why don't you use the date SQL functions and do not add them directly to your SQL query for given report in the where condition - so the report will automatically return data from the last X days without need to have any additional parameter, which you want to setup automatically anyway?

Best regards,
Juraj Ondrus

User avatar
Member
Member
lancetek - 10/21/2011 2:02:52 AM
   
RE:Using macros in report parameter defaults
I'd like to update all the reports that Kentico comes with... modifying the Sql is NOT an ideal situation. We still want to be able to override the dates when running the reports, so we just want the default dates to be dynamic, and still take manual date overrides when we wish to. Of course we could alter the sql an add case statements... but that sorta breaks upgrading doesn't it?

Kentico comes with silly report parameters - defaulting from 2003 to 2007... so when you first view a report, you don't see any data. AND the parameters are hidden, so that why you run the report, you don't have any option to change them.

So the ideal thing is to use macros in the report parameters. I suppose I *could* alter the reporting controls to allow for parsing of the macros... but I'm expecting this functionality to be built in.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/24/2011 3:39:07 AM
   
RE:Using macros in report parameter defaults
Hi,

I am sorry but I am confused. I am not sure what exactly you mean - which reports and which parameters? I tried it right now and it is possible to use macros in the parameter's default value settings - e.g. I used this macro {%currentdatetime%} to set current date/time.

Could you please describe it on some example what exactly you mean?

Best regards,
Juraj Ondrus

User avatar
Member
Member
lancetek - 10/24/2011 9:14:39 AM
   
RE:Using macros in report parameter defaults
Hi,
You are correct in that {%currentdatetime%} works fine. Is there a macro to add or subtract days from this?

Something like: {%currentdatetime%} to get a time 3 days previous.

Thanks,
Lance

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/26/2011 6:13:25 AM
   
RE:Using macros in report parameter defaults
Hi,

In version 6 you can use the K# to create such an expression.

In previous version or, also in v6 you can still create custom macro which will perform the action you want.

Best regards,
Juraj Ondrus

User avatar
Certified Developer v7
Certified  Developer v7
emanuele.firmani-aduno-gruppe - 4/22/2013 4:42:50 AM
   
RE:Using macros in report parameter defaults
I'm using Kentico 7.0.23.
I created a report with custom parameters to specify the date range.

It's working correctly when accessing it from the page CMSDesk -> Tools -> Reporting; in the View tab I'm able to change the default values, too.
When the marketer adds it to the Online marketing dashboard, he gets an exception because of a wrong datatype conversion. Same exception is thrown if I subscribe to the report.

Where am I wrong?
Thanks
Regards
Emanuele Firmani
Message: [DataConnection.HandleError]: Query: SET @FromDate = dbo.Func_Analytics_DateTrim(@FromDate,'day');
SET @ToDate = dbo.Func_Analytics_EndDateTrim(@ToDate,'day');

SELECT F.FormName, x.StartTime,
(
SELECT COUNT(1)
FROM [dbo].[View_OM_Contact_Activity] ca
WHERE CA.ActivityItemID = F.FormID
AND ActivityType = 'bizformsubmit'
AND ca.ActivityCreated BETWEEN X.StartTime AND DATEADD(day, 1, X.StartTime)
) AS 'NrSubmissions'
INTO #T
FROM (
SELECT FormID, REPLACE(FormDisplayName, 'aduno.form.', '') AS 'FormName'
FROM dbo.CMS_Form
) F
CROSS JOIN (
SELECT [Date] AS StartTime
FROM dbo.Func_Analytics_EnsureDates (@FromDate,@ToDate,'day')
) X
ORDER BY x.StartTime

DECLARE @CNames VARCHAR(MAX)
DECLARE @CName VARCHAR(MAX)
DECLARE @ColumnNames TABLE(FormName VARCHAR(900))
SET @CNames = ''

INSERT INTO @ColumnNames
SELECT DISTINCT FormName
FROM #T
ORDER BY FormName

SELECT TOP 1 @CName = FormName
FROM @ColumnNames
ORDER BY FormName

WHILE @@ROWCOUNT > 0 BEGIN
SET @CNames = @CNames + ', [' + @CName + ']'

SELECT TOP 1 @CName = FormName
FROM @ColumnNames
WHERE FormName > @CName
ORDER BY FormName
END
SET @CNames = SUBSTRING(@CNames, 3, 100000)

DECLARE @SQL VARCHAR(MAX)
SET @SQL =
'SELECT ' +
' CONVERT(VARCHAR(10), StartTime, 104) AS ''Day'', ' + @CNames +

' FROM ' +
' #T' +
' PIVOT' +
' (' +
' SUM(NrSubmissions)' +
' FOR FormName IN (' + @CNames + ')' +
' ) AS [P]'

--print(@sql)

EXEC(@SQL)

drop table #T: caused exception: The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Invalid object name '#T'.
The statement has been terminated.
Stack Trace:
at CMS.DataEngine.AbstractDataConnection.HandleError(String queryText, SqlException ex)
at CMS.DataProviderSQL.DataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction)
at CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(QueryParameters query)
at CMS.Reporting.AbstractReportControl.LoadData()
at CMSModules_Reporting_Controls_ReportTable.ReloadData(Boolean forceLoad) in e:\Farm\Aduno2Test\CMSModules\Reporting\Controls\ReportTable.ascx.cs:line 341
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Invalid object name '#T'.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at CMS.DataProviderSQL.DataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction)

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 4/23/2013 6:18:59 PM
   
RE:Using macros in report parameter defaults
Hi,

How exactly it is being added to the dashboard? Are the values, that are set on the dashboard, still returning a date data type? I mean, what is the return value of the macro?

Best regards,
Juraj Ondrus

User avatar
Certified Developer v7
Certified  Developer v7
emanuele.firmani-aduno-gruppe - 4/24/2013 1:08:37 AM
   
RE:Using macros in report parameter defaults
I added the report widget without setting any parameter: I want such parameters to be calculated depending on the current day (last 10 days, let's say) and the form for setting the parameters does not allow K# macros, only static data values.

Without setting any parameter, the report is correctly shown on my dashboard, but not on the marketer one; additionally, the report subscription doesn't work for me (it sends me an email with the error message).

Thanks
Regards

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 4/26/2013 6:19:24 PM
   
RE:Using macros in report parameter defaults
Hi,

I am little bit confused. Would you mind describing the report setup, settings and also the widget settings so I can do it on my end too to see the issue and play with it?
Thank you.

Best regards,
Juraj Ondrus