Article Details
| Id: | 11104 |
| Product: | finPOWER Connect |
| Type: | NEW |
| Version: | 1.06.08 |
| Opened: | 24/04/2013 |
| Closed: | 24/04/2013 |
| Released: | 28/05/2013 |
| Job: | J011507 |
Documents; Script can now create and use finReports library
Documents Scripts can now create and use finReports library, e.g., to utilise the Account List query.
A new option 'Allow Script to create and use Scripts and Queries' must be checked on the Document page to allow the Script access to the finReports library.
The following sample Script can be used by a Document configured as follows:
- Type: Account
- Allow Script to create and use Scripts and Queries: True
- Show in Report Explorer: True
- Parameters: Custom
Option Explicit OnOption Strict OnPrivate mQuery As ISQueryBasePrivate mReports As ISfinReportsPublic Function Main(ByVal source As Object, _ByVal eventId As String, _ByVal eventArgs As ISKeyValueList, _ByRef handled As Boolean, _ByVal parameters As Object, _ByRef returnValues As ISKeyValueList, _ByRef text As String) As Boolean' Assume SuccessMain = True' Create Reporting LayermReports = New ISfinReports(finBL)mReports.CreateQuery(isefinQueryType.AccountList, mQuery)' Handle EventsSelect Case eventIdCase "AfterParametersInitialise"' Create Document Parameters from Query ParametersWith DirectCast(parameters, ISParameters).AddParameters(mQuery.Parameters, True)End WithCase "Publish"' HTML Document is being publishedMain = Publish(DirectCast(parameters, ISKeyValueList), text)End SelectEnd FunctionPrivate Function Publish(ByVal parameters As ISKeyValueList, _ByRef html As String) As BooleanDim drv As DataRowViewDim sb As StringBuilder' Assume SuccessPublish = True' Initialisesb = New StringBuilder()' Update Query Parameters from Document ParametersmQuery.Parameters.UpdateFromKeyValueList(parameters)' Update Query Columns to include (these names can be seen when running the' Account List query Or report And looking at the exportable columns listmQuery.Columns.SetIncluded("AccountId,AccountName,Balance")' Execute QueryPublish = mQuery.Execute()' Output HTMLIf Publish Thensb.AppendLine("<html>")sb.AppendLine("<body>")sb.AppendLine("<table>")sb.AppendLine("<thead>")sb.AppendLine("<th align='left'>Account</th>")sb.AppendLine("<th align='left'>Name</th>")sb.AppendLine("<th align='right'>Balance</th>")sb.AppendLine("</thead>")sb.AppendLine("<tbody>")For Each drv In mQuery.DataSet.Tables(0).DefaultViewsb.AppendLine("<tr>")sb.AppendFormat("<td align='left'>{0}</td>", finBL.HtmlEncode(finBL.Database.GetFieldString(drv!AccountId)))sb.AppendFormat("<td align='left'>{0}</td>", finBL.HtmlEncode(finBL.Database.GetFieldString(drv!AccountName)))sb.AppendFormat("<td align='right'>{0}</td>", finBL.HtmlEncode(finBL.FormatCurrency(finBL.Database.GetFieldDecimal(drv!Balance))))sb.AppendLine("</tr>")Nextsb.AppendLine("</tbody>")sb.AppendLine("</table>")sb.AppendLine("</body>")sb.AppendLine("</html>")html = sb.ToString()End IfEnd Function
NOTE: This sample presents the User will the parameters defined on the Account List query but there is no reason that the Document could not define it's own sub-set of the parameters and update the query's parameters.