Providing report PASS_ parameters  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Providing report PASS_ parameters

Postby neil.interactit » Thu May 11, 2023 10:36 am

Hi Mike,

On one of the forms I built based on your Sample Plugin - Editable List Maintenance Form, the client went to Printer Setup (which is plumbed by default and I forgot to remove!) and added an invoice based report to print. Printing worked but was blank as it didn't know which SOE.

This would actually be a nice solution for the client, I just need to supply Pass_SP_InvoiceHistoryID based on the selected grid row.

I have tried 3 or 4 approaches, including hooking into this.ReportDefinitionCollection.ReadEnd and adding there, and overriding this.PrintRecord() and adding there - but nothing seems to work.

Could you explain the approach to use?

Cheers,
Neil.
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Providing report PASS_ parameters

Postby Mike.Sheen » Thu May 11, 2023 1:01 pm

neil.interactit wrote:On one of the forms I built based on your Sample Plugin - Editable List Maintenance Form, the client went to Printer Setup (which is plumbed by default and I forgot to remove!) and added an invoice based report to print. Printing worked but was blank as it didn't know which SOE.

This would actually be a nice solution for the client, I just need to supply Pass_SP_InvoiceHistoryID based on the selected grid row.

I have tried 3 or 4 approaches, including hooking into this.ReportDefinitionCollection.ReadEnd and adding there, and overriding this.PrintRecord() and adding there - but nothing seems to work.

Could you explain the approach to use?


Printing a list maintenance form should not require any report parameters, as it's a list so you want to print all of them in the table.

A Maintenance form (as opposed to list maintenance), such as inventory maintenance, does have a specific record identifier it wants to pass to the report - and the base form Maintenance.UserInterface will automatically set the selection formula from business logic properties.

The Maintenance Business logic has a property, RecIDFieldName which must be overridden which returns the table.column of name, for example "IN_Main.InventoryID" for the inventory maintenance business logic- we use that plus the RecID ofr the business logic to set the reports selection formula.

So, in the base class Maintenance.UserInterface, the PrintRecord method does this:
Code: Select all
SelectionFormula = "{" & BusinessLogic.RecIDFieldName & "} = " & Manager.Database.FormatChar(BusinessLogic.RecID)


Which allows all Maintenance type forms to magically have the selection formula set for you. Sales orders and other forms are a bit special and override the PrintRecord method to set report formulas themselves.

Going back to your list maintenance form and printing - you just need to override the PrintRecord method - this is what the base class ListMaintenance.UserInterface has for the PrintRecord:
Code: Select all
Public Overridable Sub PrintRecord(ByVal ReportDefinition As JiwaApplication.PrintGroup.FormReports.ReportDefinition)
   Dim PrintUIObject As JiwaApplication.JiwaPrintReportUI.MainForm
   Dim SelectionFormula As String = ""

   PrintUIObject = Manager.CreateReport(ReportDefinition, Me, 1, True, ReportDefinition.Report.ReportType = Report.Configuration.Report.ReportTypes.Menu, True, SelectionFormula)
   If Not (PrintUIObject Is Nothing) Then
      PrintUIObject.UpdateReport()
      PrintUIObject.PrintReportToScreen()
      PrintUIObject.Show()
   End If
End Sub


Override that method, and you can control everything you like - whether it's setting the SelectionFormula or setting a report formula to pass values to a stored proc.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Providing report PASS_ parameters

Postby neil.interactit » Thu May 11, 2023 3:22 pm

Hi Mike,

I'm still stuck on this.

I overrode PrintRecord(), copied in the base.PrintRecord() code, then inserted each of:
Code: Select all
this.Manager.ResetReportSelectionFormulaTokens(); // EVERY TIME, THEN ONE OF:
this.Manager.AddReportSelectionFormulaToken("{@Pass_SP_InvoiceHistoryID}", "06e326aca5ff4dd69fc8");
this.Manager.AddReportSelectionFormulaToken("{Pass_SP_InvoiceHistoryID}", "06e326aca5ff4dd69fc8");
this.Manager.AddReportSelectionFormulaToken("Pass_SP_InvoiceHistoryID", "06e326aca5ff4dd69fc8");
this.Manager.AddReportSelectionFormulaToken("{@Pass_SP_InvoiceHistoryID}", Manager.Database.FormatChar("06e326aca5ff4dd69fc8"));
this.Manager.AddReportSelectionFormulaToken("{Pass_SP_InvoiceHistoryID}", Manager.Database.FormatChar("06e326aca5ff4dd69fc8"));
this.Manager.AddReportSelectionFormulaToken("Pass_SP_InvoiceHistoryID", Manager.Database.FormatChar("06e326aca5ff4dd69fc8"));
I tried the above both before and then after report.UpdateReport(); in case that cleared something.

No matter what I try, the report Formula tab shows:
Code: Select all
__________________________________________
Pass_SP_InvoiceHistoryID Design

Pass_SP_InvoiceHistoryID Operating
''

__________________________________________

Can you spot the issue?

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Providing report PASS_ parameters  Topic is solved

Postby Mike.Sheen » Thu May 11, 2023 3:43 pm

neil.interactit wrote:Hi Mike,

I'm still stuck on this.

I overrode PrintRecord(), copied in the base.PrintRecord() code, then inserted each of:
Code: Select all
this.Manager.ResetReportSelectionFormulaTokens(); // EVERY TIME, THEN ONE OF:
this.Manager.AddReportSelectionFormulaToken("{@Pass_SP_InvoiceHistoryID}", "06e326aca5ff4dd69fc8");
this.Manager.AddReportSelectionFormulaToken("{Pass_SP_InvoiceHistoryID}", "06e326aca5ff4dd69fc8");
this.Manager.AddReportSelectionFormulaToken("Pass_SP_InvoiceHistoryID", "06e326aca5ff4dd69fc8");
this.Manager.AddReportSelectionFormulaToken("{@Pass_SP_InvoiceHistoryID}", Manager.Database.FormatChar("06e326aca5ff4dd69fc8"));
this.Manager.AddReportSelectionFormulaToken("{Pass_SP_InvoiceHistoryID}", Manager.Database.FormatChar("06e326aca5ff4dd69fc8"));
this.Manager.AddReportSelectionFormulaToken("Pass_SP_InvoiceHistoryID", Manager.Database.FormatChar("06e326aca5ff4dd69fc8"));
I tried the above both before and then after report.UpdateReport(); in case that cleared something.

No matter what I try, the report Formula tab shows:
Code: Select all
__________________________________________
Pass_SP_InvoiceHistoryID Design

Pass_SP_InvoiceHistoryID Operating
''

__________________________________________

Can you spot the issue?

Cheers,
Neil


If you're using our standard invoice report, or a report based on that, then I believe you need to push the values of the tokens from the Manager.ReportSelectionFormulaTokens into the formulas.

As we audit printing of sales orders in the SO_PrintLog table, we would normally want you to use the sales order business logic to print a report instead of just printing directly - as that'll enforce the right permissions and also create the entry in the SO_PrintLog table.

But, if you were to just print directly from another form, not use the sales order business logic, it would be something like the following.

I can't test this myself right now, but I believe you want to do the following after the CreateReport() , but before the UpdateReport():
Code: Select all
Manager.AddReportSelectionFormulaToken("{@Pass_InvoiceHistoryID}", "06e326aca5ff4dd69fc8")

For MyLoop As Integer = 1 To Manager.GetReportSelectionFormulaTokenCount
   Dim tokenName As String = ""
   Dim tokenValue As Object = Nothing

   Manager.GetReportSelectionFormulaToken(MyLoop, tokenName, tokenValue)

   For Each m_JiwaReportRange As JiwaApplication.JiwaPrintReport.JiwaReportRange In PrintUIObject.PrintReportObject.JiwaReportRangeCollection
      If PrintUIObject.PrintReportObject.JiwaPrintFormulaCollection(m_JiwaReportRange.FormulaKey).Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() = tokenName.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() Then
         m_JiwaReportRange.Value = CStr(tokenValue)
         Exit For
      End If
   Next m_JiwaReportRange
Next MyLoop


That goes through all the tokens in the Manager and finds any formulas in the report which contain the token and replace it with the token value - so the {@Pass_InvoiceHistoryID} token will get replaced with the literal "06e326aca5ff4dd69fc8". You don't have to do every token - you could just look for formulas in the report which contain "{@Pass_InvoiceHistoryID}" and replace that with the desired value, but you never know what other tokens are expected to be set by the report, so it's good practice to just set them all.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Providing report PASS_ parameters

Postby neil.interactit » Thu May 11, 2023 6:37 pm

Perfect! Thanks Mike.

In case anyone else is looking, here is the final working code ...
Code: Select all
    public override void PrintRecord(ReportDefinition ReportDefinition)
    {
        //START implemented elsewhere, included for context
        //this.Manager.ResetReportSelectionFormulaTokens();
        //this.Manager.AddReportSelectionFormulaToken("{@Pass_SP_InvoiceHistoryID}", "06e326aca5ff4dd69fc8");
        //END implemented elsewhere, included for context
        //START copied from base.PrintRecord(ReportDefinition)
        var recordSelectionFormula = "";
        var report = this.Manager.CreateReport(ReportDefinition, (IJiwaForm)this, ShowRanges: ReportDefinition.Report.ReportType == JiwaFinancials.Jiwa.JiwaApplication.Report.Configuration.Report.ReportTypes.Menu, PromptUser: true, RecordSelectionFormula: recordSelectionFormula);
        if (report == null) return;
        //END copied from base.PrintRecord(ReportDefinition)
        for (var myLoop = 1; myLoop <= Manager.GetReportSelectionFormulaTokenCount(); myLoop++)
        {
            var tokenName = "";
            object tokenValue = null;
            Manager.GetReportSelectionFormulaToken(myLoop, ref tokenName, ref tokenValue);
            foreach (JiwaReportRange reportRange in report.PrintReportObject.JiwaReportRangeCollection)
            {
                if (report.PrintReportObject.JiwaPrintFormulaCollection[reportRange.FormulaKey].Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() != tokenName.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper()) continue;
                reportRange.Value = tokenValue.ToString();
            }
        }
        //START copied from base.PrintRecord(ReportDefinition)
        report.UpdateReport();
        report.PrintReportToScreen();
        report.Show();
        //END copied from base.PrintRecord(ReportDefinition)
    }

Thanks again Mike!
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 23 guests