How to access remote Jiwa database  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

How to access remote Jiwa database

Postby DannyC » Wed Aug 26, 2020 5:24 pm

Using this sample
viewtopic.php?f=27&t=491
I have had something in place at a client for a little while now, using 7.0.175. In my case, they're in a Purchase Order & it creates a sales order in the remote database.

They've recently upgraded to 7.2.1 and although the basis of the plugin is still sound, they are getting odd behaviour. I think it is something to do with the SessionIDs. When the transaction has completed in the other database, Jiwa changes the main warehouse and weird stuff happens with the menu.

I know Instance is deprecated so I was wondering what would be the best alternative to the line
Code: Select all
Dim databaseSessionID As String = JiwaFinancials.Jiwa.JiwaApplication.Session.Instance.SessionID


And then when getting back to the current session, is this still OK?
Code: Select all
'Set our session back to the currently logged in database
JiwaFinancials.Jiwa.JiwaApplication.Session.Instance.SessionID = databaseSessionID


Cheers
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: How to access remote Jiwa database

Postby SBarnes » Wed Aug 26, 2020 8:21 pm

Simple, you create a manger and login like this, the work with creating objects from the managers factories, believe it or not I am pretty sure you have done this before.


Code: Select all
 manager2 = new Manager();
 manager2.Logon("DatabaseServer", "DatabaseName", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password");
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: How to access remote Jiwa database

Postby DannyC » Wed Aug 26, 2020 10:47 pm

its not the logging on. I already have that sussed.

It is the setting of the variable for the current session in the current database, then returning to that current session which is an issue.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: How to access remote Jiwa database

Postby SBarnes » Wed Aug 26, 2020 10:59 pm

You don’t need to do that just logon to the second manger do what you need to do and log off.

The original manager will remain unchanged.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: How to access remote Jiwa database  Topic is solved

Postby Scott.Pearce » Thu Aug 27, 2020 9:46 am

Yeah don't use instance anymore and don't use sessionIDs.

So, you want to do something like create a document in another Jiwa database? You instantiate a manager object FOR THE REMOTE DATABASE and log on to it:

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager DB2Manager = new JiwaFinancials.Jiwa.JiwaApplication.Manager();
DB2Manager.Logon(DB2ServerName, DB2DatabaseName, JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, DB2UserName, DB2Password);


Now any operation you want to perform in the remote database, just use your DB2Manager variable. For example, I want to create a PO in DB2, let's take it from the top, creating my manager object for the remote database, logging in, creating the PO, saving it, logging out of the remote database:

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager DB2Manager = new JiwaFinancials.Jiwa.JiwaApplication.Manager();
DB2Manager.Logon(DB2ServerName, DB2DatabaseName, JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, DB2UserName, DB2Password);

try
{
    JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder DB2PurchaseOrder = DB2Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder>(null);
    DB2PurchaseOrder.CreateNew(JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder.SupplierType.Creditor, JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder.NewOrderSeedTypes.CreditorAccountNo, "1001", JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder.PurchaseOrderType.DefaultOrderType, "ZZZZZZZZZZ0000000000");
    DB2PurchaseOrder.Save();
}
finally
{
    DB2Manager.LogOff();
}


Note how I used a try finally block to ensure I always logged off from DB2Manager! That's it. No sessions ids to juggle. Just create a manager object for the remote database and use it. You could have a number of manager object variables on the go at once, each looking at a different remote database.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: How to access remote Jiwa database

Postby SBarnes » Thu Aug 27, 2020 9:51 am

Of course this all assumes that both databases are accessible to the client and can be logged onto and are the same version, if they weren't you'd be up to resorting to using the Rest API to follow the sames steps, that would work for instance with Jiwas at different sites like interstate offices.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest