Cashbook receipt Jiwa crash when desc blank  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Cashbook receipt Jiwa crash when desc blank

Postby indikad » Thu Apr 14, 2022 10:05 pm

Jiwa 7.2.1
Window: Cash book Payment
Issue replication: Create a new Payment , go straight to type a value on the new transaction line and tab out - Jiwa crashes
If you have some text in the Header Description field then all is well

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      if(JiwaForm is JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBook)
      {
         JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBook cashBookForm = (JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBook)JiwaForm;         
         _cashBookForm =  cashBookForm;
         _Plugin = Plugin;         
         cashBookForm.CashBook.CashBookTransactions.Added += CashBook_TransactionAdded;            
         cashBookForm.CashBook.CashBookTransactions.Changed  += CashBookTransactions_Changed;
      }      
    }
   private void CashBook_TransactionAdded(JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransaction item)
   {   
      try
      {
         if (_cashBookForm.CashBook.Description.ToString().Length > 0 )
         {
            item.Remark =  _cashBookForm.CashBook.Description.ToString() ;   
         }            
         item.PaymentType.ReadRecord ("000000001Z00000000RH"); // demodata setting to AMX                  
      }
      catch(Exception ex)
      {
         MessageBox.Show("Error setting transaction properties in trx add err: " + ex.Message , "Plugin: " + _Plugin.Name  , MessageBoxButtons.OK , MessageBoxIcon.Error  );
      }      
   }
   private void CashBookTransactions_Changed(JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransaction item , System.ComponentModel.PropertyChangedEventArgs e )
   {         
      try
      {         
         if (e.PropertyName.Trim().ToUpper() != "JOBCHARGEAMOUNT" )
         {               
            item.JobChargeAmount = item.HomeAmount * ( (decimal) 1.1 ) ;
         }
         if ( item.Remark.Trim().Length == 0 )
         {
            item.Remark =  _cashBookForm.CashBook.Description.ToString();
         }            
      }
      catch(Exception ex)
      {
         MessageBox.Show("Error setting transaction properties in trx change err: " + ex.Message , "Plugin: " + _Plugin.Name  , MessageBoxButtons.OK , MessageBoxIcon.Error  );
      }   
   }
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Cashbook receipt Jiwa crash when desc blank

Postby SBarnes » Fri Apr 15, 2022 9:07 am

Hi Indika

I tried to replicate your issue in a demo database under 7.2.1 and can't make it fall over, but this copy of Jiwa has the latest service release installed, are you working with the latest service release and are there any other plugins that could be having a side effect on things?

I would try it on a clean demo database with the latest service release installed and see if the issue is still there.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Cashbook receipt Jiwa crash when desc blank

Postby indikad » Tue Apr 19, 2022 12:51 pm

its the CashBookTransactions.Changed event. looks like it gets hit repeatedly until stack overflows.

-- and there are no other plugins interfering
-- also separated the two event calls to two plugins as a test that has not helped.

-- could be the SR , will have a look
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Cashbook receipt Jiwa crash when desc blank

Postby SBarnes » Tue Apr 19, 2022 2:34 pm

Does it happen if the code you have included is disabled ?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Cashbook receipt Jiwa crash when desc blank

Postby indikad » Tue Apr 19, 2022 4:06 pm

if I disable the changed event it does not happen.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Cashbook receipt Jiwa crash when desc blank  Topic is solved

Postby SBarnes » Tue Apr 19, 2022 4:20 pm

Ah then the answer is simple the reason it crashes is because your code in the change event is causing the change event to fire again.

This is similar to recursion with no base case in that the function keeps calling itself endlessly.

What you need to do is kind of similar to how you attached it in that you detach the event, but with a minus instead of the plus which you do at the top of your code, do your code and then reattach the handler at the bottom of your code same as is done in the setup.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Cashbook receipt Jiwa crash when desc blank

Postby indikad » Wed Apr 20, 2022 10:33 am

Applying the SR fixed it.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Cashbook receipt Jiwa crash when desc blank

Postby indikad » Wed Apr 20, 2022 1:50 pm

I thought it had fixed with the SR11 but in fact it hadn’t.

I had to place your workaround of detaching the event to get it working. Thanks for that.
it's interesting that it wont "self heal" . I was sure I had written similar plugin code before without having the recursion issue. (may be I am wrong.)
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Cashbook receipt Jiwa crash when desc blank

Postby SBarnes » Wed Apr 20, 2022 2:22 pm

I will be honest when you said the service release had fixed it I was surprised.

As the problem you were having is not uncommon in that the event handler causes the event to fire, and is a common issue to events not just JIWA, the other way you can deal with the issue is to use some sort of Boolean flag and return at the top of the handler if the flag is set but the detach handler option is cleaner and less code.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Cashbook receipt Jiwa crash when desc blank

Postby indikad » Wed Apr 20, 2022 5:51 pm

agree about the recursion effect is a common issue.

I was actually talking in Jiwa context. I do have some other similar codlings on Jiwa that did not require this intervention. Will have a look and come back when I get some time to spend.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 12 guests

cron