Page 1 of 1

Getting a report name in Settings ButtonClick

PostPosted: Thu Jul 11, 2019 5:51 pm
by pricerc
Do I have this right?

Code: Select all
        Public Sub ButtonClicked(ByVal BusinessLogicHost As IJiwaBusinessLogic, ByVal GridObject As Controls.JiwaGrid,
                                 ByVal FormObject As IJiwaForm,
                                 ByVal Col As Integer, ByVal Row As Integer,
                                 ByVal SystemSetting As JiwaApplication.SystemSettings.Setting) Implements IJiwaSystemSettingPlugin.ButtonClicked
            If Debugger.IsAttached Then Debugger.Break()

            Dim activeSheet As FarPoint.Win.Spread.SheetView = GridObject.ActiveSheet
            Dim activeCell As FarPoint.Win.Spread.Cell = activeSheet.Cells(Row, Col)

            If String.Compare(SystemSetting.IDKey, "ReportName", StringComparison.InvariantCultureIgnoreCase) = 0 Then

                Dim reportSearch As clsSearch = BusinessLogicHost.Manager.Search
                reportSearch.Clear()
                reportSearch.SetDefaultSearch(clsSearch.SearchModes.jswReports)
                reportSearch.Caption = "Reports"

                If (reportSearch.Show(FormObject.Form) <> System.Windows.Forms.DialogResult.OK) OrElse (reportSearch.Results.Count <> 1) Then
                    Return
                End If

                ' 1 == first result (Because 1-based array returned from legacy dialog)
                ' 4 == field # for file name in search (potential breaking change with future versions.
                Dim reportFileName = CStr(reportSearch.Result(1).Fields(4).FieldValue)

                SystemSetting.Contents = reportFileName

            End If
        End Sub


I'm not crazy about the hard-coded '4', but in the debugger (as far as I can tell), the alternative is a hard-coded "File Name4", which seemed just as bad.

Re: Getting a report name in Settings ButtonClick  Topic is solved

PostPosted: Thu Jul 11, 2019 6:05 pm
by Scott.Pearce
The rule with searches is that field #1 will always be a unique recID of the record selected and this is what should be primarily used.

In your example, field #1 will give you SY_Report.RecID. *THIS* is the value you should be saving into SystemSettings.Contents as it is what uniquely identifies any given report.

In your plugin, the SystemSettingPlugin.ReadData() function should then be used to get SystemSetting.Contents (which is SY_Report.RecID), resolve it to a report filename/title by doing a read on SY_Report (or by using the Report entity), and putting that resolved report filename/title into System.DisplayContents - I would use the JiwaApplication.Entities.Reports.ReportDefinition to read based on RecID to obtain filename.

Re: Getting a report name in Settings ButtonClick

PostPosted: Thu Jul 11, 2019 10:52 pm
by pricerc
Scott.Pearce wrote:The rule with searches is that field #1 will always be a unique recID of the record selected and this is what should be primarily used.

In your example, field #1 will give you SY_Report.RecID. *THIS* is the value you should be saving into SystemSettings.Contents as it is what uniquely identifies any given report.

In your plugin, the SystemSettingPlugin.ReadData() function should then be used to get SystemSetting.Contents (which is SY_Report.RecID), resolve it to a report filename/title by doing a read on SY_Report (or by using the Report entity), and putting that resolved report filename/title into System.DisplayContents - I would use the JiwaApplication.Entities.Reports.ReportDefinition to read based on RecID to obtain filename.


So that was what I was expecting, and I had more-or-less that code in my plugin (although I was looking at Result(1).RecID, not Result(1).Fields(1), which is why it didn't work and why I ended up in the debugger).

But since FileName is a unique index on SY_Reports, I decided that would be fine for my purposes. This isn't something that's going to get changed much after being set up. Also, if I use the ID, then I need to then handle displaying it the System Settings screen, whereas using the file name means I don't have to. In fact, I *was* going to just have the file name as a text field (easy enough to copy-in from the Reports management screen), I decided to do the report lookup as an exercise, because I thought it would be useful.

When I'm next working on something that is likely to be changed often, I'll be a bit more particular.