Register a custom function in a report

Stimulsoft Reports.WEB discussion
Post Reply
Enrique
Posts: 6
Joined: Fri Jul 29, 2016 3:09 pm

Register a custom function in a report

Post by Enrique »

Hello.

We have included a custom function directly in the report code:

Public Class Report

Inherits Stimulsoft.Report.StiReport

Public Sub New()
MyBase.New
Me.InitializeComponent
End Sub

Public Function EN(palabra As String, listaPalabras As list(Of String)) As Boolean
For Each key As String In listaPalabras
If palabra = key Then
Return (True)
Else
Return (False)
End If
Next
End Function

#Region "StiReport Designer generated code - do not modify"
#End Region 'StiReport Designer generated code - do not modify
End Class

Can we include and register this function in the functions dictionary of the report?. Can you provide to us a sample of how to do it?

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Register a custom function in a report

Post by Alex K. »

Hello,

Please check the following code:

Code: Select all

Public Class MyFunction
    Private Const Category As String = "MyFuncCategory"

    Public Shared Function MyFunc(value As String) As String
        Return value.ToUpper()
    End Function

    Public Shared Sub RegisterFunctions()
        Dim ParamNames = New String(0) {}
        Dim ParamTypes = New Type(0) {}
        Dim ParamDescriptions = New String(0) {}

        ParamNames(0) = "value"
        ParamDescriptions(0) = "Descriptions"
        ParamTypes(0) = GetType(String)

        Stimulsoft.Report.Dictionary.StiFunctions.AddFunction(Category, "MyFunc", "MyFunc", "Description", GetType(MyFunction), GetType(String),
            "Return Description", ParamTypes, ParamNames, ParamDescriptions)
    End Sub
End Class
Thnak you.
Attachments
Capture.PNG
Capture.PNG (52.9 KiB) Viewed 6946 times
jserret
Posts: 23
Joined: Mon May 09, 2016 10:51 am

Re: Register a custom function in a report

Post by jserret »

Hello,

I have the same problem, in a new report I copied your code and I get an error "referencedAssemblies" .

I attaching the Mrt and a screenshot of the error (Sorry the screenshot are in spanish)

Might you help me?

Thank you
Attachments
Screenshot error
Screenshot error
2016-09-21_11-55-13.png (19.69 KiB) Viewed 6945 times
test.mrt
Report test
(4.19 KiB) Downloaded 252 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Register a custom function in a report

Post by Alex K. »

Hello,

We have found the issue with adding a custom function when selected VB script language for the report.
The issue is fixed. Will be available in the next prerelease build.

At the current moment, you can use the several ways:
- add this code for adding function to your application, not in the designer's Code tab
- select CSharp script language (attached report ReportC.mrt)

Thank you.
Attachments
ReportC.mrt
(4.08 KiB) Downloaded 444 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Register a custom function in a report

Post by Alex K. »

Hello,

Also, please check the modified report with VB script.

Thank you.
Attachments
ReportVb2.mrt
(4.35 KiB) Downloaded 554 times
jserret
Posts: 23
Joined: Mon May 09, 2016 10:51 am

Re: Register a custom function in a report

Post by jserret »

Aleksey wrote:Hello,

We have found the issue with adding a custom function when selected VB script language for the report.
The issue is fixed. Will be available in the next prerelease build.

At the current moment, you can use the several ways:
- add this code for adding function to your application, not in the designer's Code tab
- select CSharp script language (attached report ReportC.mrt)

Thank you.
Thanks, We'll wait for this issue fixed in the next build.

Aleksey wrote:Hello,

Also, please check the modified report with VB script.

Thank you.
This example if it works, but I still can add the function to the dictionary, is not visible


Thanks for you help, and I hope that the next build work
Attachments
2016-09-21_17-31-51.png
2016-09-21_17-31-51.png (3.5 KiB) Viewed 6942 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Register a custom function in a report

Post by Alex K. »

Hello,

Yes. In the EndRender event, this function is removed.
Please check the next build.

Thank you.
lboers61
Posts: 2
Joined: Wed Sep 26, 2018 1:45 pm

Re: Register a custom function in a report

Post by lboers61 »

Hi Alex,

Starting from which version/build should this be solved?

Thanks for answering,
Leen
lboers61
Posts: 2
Joined: Wed Sep 26, 2018 1:45 pm

Re: Register a custom function in a report

Post by lboers61 »

Hi Alex,

Starting from which version/build should this be solved?

Thank you.
Lech Kulikowski
Posts: 6247
Joined: Tue Mar 20, 2018 5:34 am

Re: Register a custom function in a report

Post by Lech Kulikowski »

Hello,

Starting from 2016.3

Thank you.
Post Reply