How to add BusinessLogic event on custom BusinessLogic  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

How to add BusinessLogic event on custom BusinessLogic

Postby sameermoin » Wed May 10, 2023 4:58 pm

Hi,

I have one custom plugin in which I have one custom form inheriting JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Configuration class. Like in other forms such as the Inventory maintenance form, we have SaveEnd, SaveStart, and other events I want to implement one of them in the custom form. The custom business logic class has been implemented as a .NET library and embedded into the plugin as a dll 

Although I am getting the events, none of them are working.

Code: Select all
public partial class WebMaintenance : JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Configuration
{
   //custom logic
}


And this is how I am trying to use it:

Code: Select all
if (JiwaBusinessLogic is CustomBusinessLogic.BusinessLogic.WebMaintenance)
{
      CustomBusinessLogic.BusinessLogic.WebMaintenance webMaintenance = (CustomBusinessLogic.BusinessLogic.WebMaintenance)JiwaBusinessLogic;

      webMaintenance.SaveEnd += delegate (object sender, EventArgs e)
      {

      };
}
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: How to add BusinessLogic event on custom BusinessLogic

Postby Mike.Sheen » Wed May 10, 2023 8:57 pm

sameermoin wrote:Although I am getting the events, none of them are working.


What does that mean? If you are getting the event, then it is working. What do you mean by it is not working?

You have not provided enough information to help you. Perhaps if you provided a sample plugin illustrating the problem, we could help you more.
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: How to add BusinessLogic event on custom BusinessLogic

Postby Nina@Opal » Fri May 12, 2023 3:49 pm

Hi Mike,

We have created a .NET class library to implement custom business logic and referenced it in a plugin as an embedded reference.

The business logic class inherit from Jiwa configuration business logic base class JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Configuration.

Then we wanted to hook into the business logic object SaveEnd event from another plugin. We added a plugin reference to the second plugin we are developing and we noticed that the code intellisense in the code editor works as expected, but the subscribed SaveEnd event does not trigger as expected.

Do we need to do anything else other than referencing first plugin we did in order to get this working?

Thanks
Nina
Nina@Opal
I'm new here
I'm new here
 
Posts: 5
Joined: Wed Sep 22, 2021 8:31 am

Re: How to add BusinessLogic event on custom BusinessLogic

Postby SBarnes » Fri May 12, 2023 5:42 pm

Hi Nina,

Below is the code for the object you are inheriting from in terms of its save so I will assume you have implemented iSave with no code to reference to get at the specifics like Mike asked on this post previously this is a guess at best


Code: Select all
 Protected MustOverride Sub iSave() Implements IJiwaSaveable.iSave
        Public Sub Save() Implements IJiwaSaveable.Save
            Try
                iSave()
            Catch ex As JiwaODBC.Exceptions.SQLTransactionIsZombied
                Dim retryCount As Integer = 0
                Dim retryInterval As Integer

                If Manager.Database.RetriesOnTransientFailure > 0 Then
                    Do While retryCount <= Manager.Database.RetriesOnTransientFailure
                        Try
                            If retryCount > 0 Then
                                Thread.Sleep(retryInterval) 'Exponential back-off
                            End If
                            iSave()
                            Exit Do
                        Catch ex2 As Exception
                            iSave()
                            Exit Do
                        End Try
                        retryInterval += Manager.Database.RetryBaseMillisecondsInterval * retryCount
                        retryCount += 1
                    Loop
                    Throw
                Else
                    Throw
                End If
            Catch ex3 As Exception
                Throw
            End Try
        End Sub


There are also three methods that will raise the save events namely those shown below these should go in the appropriate places within your iSave code to call any attached events to trigger

Code: Select all
Public Overridable Sub OnSaveStart()
            RaiseEvent SaveStart(Me, New System.EventArgs)
        End Sub

        Public Overridable Sub OnSaveEnding()
            RaiseEvent SaveEnding(Me, New System.EventArgs)
        End Sub

        Public Overridable Sub OnSaveEnd()
            RaiseEvent SaveEnd(Me, New System.EventArgs)
        End Sub



An example of this is the iSave from General Ledger configuration that looks like this and is a class that inherits from the class you mentioned, note that the difference between ending and end is ending should be called before any database commits and end should be called as the last thing.

Code: Select all
 Protected Overrides Sub iSave()
        Dim weStartedTransaction As Boolean

        With Manager.Database
            Try
                If .SQLTransaction Is Nothing Then
                    ' flag that we created the transaction, so we know if we should be the ones to .commit or .rollback later.
                    .BeginNewTransaction()
                    weStartedTransaction = True
                End If

                OnSaveStart()

                ' Validate no years or periods overlap and ensure Year staring dates match Period 1 starting date
                Years.Validate()

                Years.Save()
                Manager.Database.SaveSysData("GLParams", "SegmentSeparator", _Separator)
                Segments.Save()

                OnSaveEnding()

                If weStartedTransaction Then
                    .SQLTransaction.Commit()
                    .SQLTransaction.Dispose()
                    .SQLTransaction = Nothing
                End If

                Manager.GeneralLedgerConfiguration.Read()

                OnSaveEnd()

            Catch ex As Exception
                If weStartedTransaction AndAlso .SQLTransaction IsNot Nothing Then
                    If .SQLTransaction.Connection IsNot Nothing Then
                        .SQLTransaction.Rollback()
                    End If
                    .SQLTransaction.Dispose()
                    .SQLTransaction = Nothing
                End If

                Throw
            Finally
                If weStartedTransaction Then
                    .SQLTransaction = Nothing
                End If
            End Try
        End With

    End Sub
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: How to add BusinessLogic event on custom BusinessLogic

Postby Mike.Sheen » Fri May 12, 2023 5:46 pm

Nina@Opal wrote:Do we need to do anything else other than referencing first plugin we did in order to get this working?


Without seeing your code, I can't be sure, but it's probably because in your Save method you are not calling the OnSaveEnd() method.
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: How to add BusinessLogic event on custom BusinessLogic

Postby sameermoin » Mon May 15, 2023 8:02 pm

Check the attached example plugin with a custom "Lib.LibBusinessLogic" business logic. The embedded library code is also linked in the plugin document section.

Plugin Embedded Lib Plugin.xml
(62.52 KiB) Downloaded 53 times
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: How to add BusinessLogic event on custom BusinessLogic

Postby SBarnes » Tue May 16, 2023 8:37 am

Ok having had a quick look at things the embedded code looks ok but what I suspect you problem is, as I haven't tested this, is that under the business logic tab you do not have your business logic object listed so Jiwa doesn't look for your business object being created and setup to call the business logic setup call in the plugin.

You need an entry in the SY_BusinessLogic table to make this happen and then add it under the business logic tab in the plugin. The SQL for the search screen on that tab is below, have a look at entries in table to see what to do.

The other thing is your embedded solution is using .net framework 4.7.2 you will need to install this on any machine running Jiwa, switch it back to 4.7.1 if you can to make your life easier.


Code: Select all
SELECT RecID, Description, AssemblyFullName, ClassName FROM SY_BusinessLogic
ORDER BY Description


This why providing a plugin and not just snippets of code is always a quicker way to reach an answer as in this case the problem may not be the actual code itself but rather the plugin setup.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: How to add BusinessLogic event on custom BusinessLogic

Postby Mike.Sheen » Tue May 16, 2023 11:00 am

This is precisely as Stuart described.

Attached is a modified version of the plugin which works.

It has a SQL Script attached to the documents tab, which when run will register the business logic.

Once run, you could then add the business logic to the business logic references tab of the plugin.

So, you need to import the attached plugin, save, then run the attached SQL script, then exit, log back in and it will work as expected.
Attachments
Plugin Embedded Lib Plugin.xml
(67.1 KiB) Downloaded 47 times
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: How to add BusinessLogic event on custom BusinessLogic

Postby sameermoin » Wed May 17, 2023 3:23 pm

I installed the attached plugin but I am getting an object reference null error when logging in Jiwa.

jiwa error.png
jiwa error.png (21.22 KiB) Viewed 2576 times


It will work fine if I put the Lib.dll in the jiwa Installation directory. In production, we can't put the custom dll in the Jiwa directory.
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: How to add BusinessLogic event on custom BusinessLogic  Topic is solved

Postby Mike.Sheen » Wed May 17, 2023 4:45 pm

sameermoin wrote:I installed the attached plugin but I am getting an object reference null error when logging in Jiwa.

jiwa error.png


It will work fine if I put the Lib.dll in the jiwa Installation directory. In production, we can't put the custom dll in the Jiwa directory.


Odd - I get it now, too - but not when I first enabled the plugin and logged out and logged in.

What you're trying to do with this plugin isn't something we'd anticipated - you have an embedded dll reference you want registered as a business logic object, and to reference that same object in the same plugin - and that's not a normal pattern.

I've logged DEV-9989 to look at this, but in the meantime, don't embed your business logic as an embedded reference, but just inside the plugin itself. If you want other plugins to reference it, they can by adding a plugin reference.

What you are trying to do is hide whatever is in your business logic - and that's not something we encourage as it can mean the customer is left in a potentially unsupportable situation in the future. Whatever code you have in there isn't as special or important as you may think.
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


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 15 guests