SR17 JournalSet.iSave issue  Topic is solved

Discussions relating to the REST API of Jiwa 7.

SR17 JournalSet.iSave issue

Postby neil.interactit » Tue Oct 17, 2023 5:27 pm

Hi guys,

I am upgrading a client to Version 07.02.01.00 SR17 (from SR13).

A failure has arisen in a REST API Custom Routes plugin implementation. This has been updated with the using (var manager = this.Request.GetManager()) change due to the updated REST API plugin, and testing shows the manager appears to be being created successfully.

The error is:
Object reference not set to an instance of an object.
at JiwaFinancials.Jiwa.JiwaODBC.database.BeginNewTransaction(IsolationLevel IsolationLevel)
at JiwaFinancials.Jiwa.JiwaODBC.database.BeginNewTransaction()
at JiwaFinancials.Jiwa.JiwaJournalSets.JournalSet.iSave()
at JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Maintenance.Save()
as a result of executing a
Code: Select all
   journalSet.Save();


journalSet is created with:
Code: Select all
private JournalSet GetOrCreateJournalSet(Manager manager, string description, DateTime postedDate)
{
   var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
   var results = Db.SqlList<GL_Sets>("SELECT TOP 1 * FROM GL_Sets WHERE Description = @Description AND SetType = 2 AND PostDateTime = @PostDateTime", new { Description = description, PostDateTime = postedDate });
   if (results.Any())
      journalSet.Read(results.First().GLSetID);
   else
   {
      journalSet.CreateNew();
      journalSet.Description = description;
      journalSet.PostedDate = postedDate;
      journalSet.Source = "Local";
      journalSet.SetType = JournalSet.SetTypes.Pending;
   }
   return journalSet;
}

Then has lines added via:
Code: Select all
   var journalLine = manager.CollectionItemFactory.CreateCollectionItem<Line>();
   ...
   journalSet.Lines.Add(journalLine);

I can't spot anything else significant. This works for SR13 (with the older REST API plugin).

Is this enough detail for you to see how I am incorrectly instantiating journalSet and/or journalLine for SR17, or something else I am missing that is now needed?

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

Re: SR17 JournalSet.iSave issue

Postby SBarnes » Wed Oct 18, 2023 7:05 am

Hi Neil,

It's probably better that you post the entire plugin rather than snippets as then it would be possible to run it through the debugger and see what is going on.

The other way of going is of course you could actually call the Jiwa routes themselves for journals by filling in the dto request objects for either post or patch on a journal and then calling post or patch on the journal service, if you look in the rest api you should be able to figure out the service class and then you can use ServiceStack's ResolveService call to get the class look at this link on how to do it https://stackoverflow.com/questions/238 ... ntent-type
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: SR17 JournalSet.iSave issue

Postby neil.interactit » Wed Oct 18, 2023 10:28 am

Thanks Stuart.

I created a new RestApiFailingJournalSetSaveMinimal plugin with a single route and just the JournalSet create and save. AND IT WORKED. Bummer.

So I will progressively add more in from the failing plugin code and should be able to work out the issue.

I'll update this thread either with what the fix was, or a failing plugin sample.

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

Re: SR17 JournalSet.iSave issue

Postby Mike.Sheen » Wed Oct 18, 2023 10:33 am

neil.interactit wrote:I created a new RestApiFailingJournalSetSaveMinimal plugin with a single route and just the JournalSet create and save. AND IT WORKED. Bummer.


That is excellent news!
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: SR17 JournalSet.iSave issue  Topic is solved

Postby neil.interactit » Thu Oct 19, 2023 8:52 am

Mike nailed this offline for me.

In case it helps others ...

Any Jiwa server release upgrade from before SR15 to on or after SR15 involves breaking changes for REST API based plugins per https://jiwa.atlassian.net/wiki/spaces/J7UG/pages/9863169/Jiwa+7.02.01.00+Service+Release+15#BreakingChanges ...
Code which was like this:
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager manager = this.GetManager();
// other service method code in here

Needs to change to this:
Code: Select all
using(JiwaFinancials.Jiwa.JiwaApplication.Manager manager = this.Request.GetManager())
{
  // other service method code in here
}


In my case the change (vastly simplified) was from:
Code: Select all
JournalSet journalSet = null;
var manager = this.Request.GetManager();
var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
journalSet.Save();

To:
Code: Select all
JournalSet journalSet = null;
using (var manager = this.Request.GetManager())
{
   var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
}
journalSet.Save();

What I missed, that is not visually apparent, is that the BusinessLogicFactory passes manager into journalSet causing the error on Save as manager is disposed by then.

The solution was:
Code: Select all
JournalSet journalSet = null;
using (var manager = this.Request.GetManager())
{
   var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
   journalSet.Save();
}

Thanks Mike!

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

Re: SR17 JournalSet.iSave issue

Postby SBarnes » Thu Oct 19, 2023 9:31 am

Hi Neil,

Yeah the the best thing to do going forward is create the manager in a using clause that surrounds all other code with its braces.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to REST API

Who is online

Users browsing this forum: No registered users and 4 guests

cron