New debtor, assign a group when created  Topic is solved

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

New debtor, assign a group when created

Postby DannyC » Mon Nov 29, 2021 5:06 pm

When a new debtor is created, I want to add a particular group.

So far my code reads:
Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   if (JiwaForm is JiwaFinancials.Jiwa.JiwaDebtorsUI.frmDebtor)
   {
      JiwaFinancials.Jiwa.JiwaDebtorsUI.frmDebtor debtorForm = (JiwaFinancials.Jiwa.JiwaDebtorsUI.frmDebtor)JiwaForm;
      debtorForm.Debtor.CreateEnd += DebtorNewGroup;
   }      
}
   
private void DebtorNewGroup(object sender, System.EventArgs e)
{
   System.Diagnostics.Debugger.Launch();
   JiwaFinancials.Jiwa.JiwaDebtors.Debtor debtor = (JiwaFinancials.Jiwa.JiwaDebtors.Debtor)sender;
   JiwaFinancials.Jiwa.JiwaDebtors.Group dbGroup = new JiwaFinancials.Jiwa.JiwaDebtors.Group();
   dbGroup.Group.ReadRecord("00614AA4EC754C7AA2D1");
   debtor.Groups.Add(dbGroup);
}


but dbGroup is null. I know I'm missing something but what? I got the ID "00614AA4EC754C7AA2D1" from looking in the CN_Groups table and just getting the groupID I want to add.

Version 7.2.1 SR5.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: New debtor, assign a group when created  Topic is solved

Postby Mike.Sheen » Mon Nov 29, 2021 5:12 pm

Code: Select all
JiwaFinancials.Jiwa.JiwaDebtors.Group dbGroup = new JiwaFinancials.Jiwa.JiwaDebtors.Group();


This will cause problems on versions 7.00.177.00 or later - you should be using the factory!

Code: Select all
JiwaFinancials.Jiwa.JiwaDebtors.Group dbGroup = Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaDebtors.Group>();


Or maybe you are using an earlier version than 7.00.177.00 ?
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: New debtor, assign a group when created

Postby DannyC » Mon Nov 29, 2021 9:24 pm

Sweet. That sorted it out.

For those playing along at home, this code adds a new group with the staff Admin. The default tickbox is automatically set.

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   if (JiwaForm is JiwaFinancials.Jiwa.JiwaDebtorsUI.frmDebtor)
   {
      JiwaFinancials.Jiwa.JiwaDebtorsUI.frmDebtor debtorForm = (JiwaFinancials.Jiwa.JiwaDebtorsUI.frmDebtor)JiwaForm;
      debtorForm.Debtor.CreateEnd += DebtorNewGroup;
   }      
}
   
private void DebtorNewGroup(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaDebtors.Debtor debtor = (JiwaFinancials.Jiwa.JiwaDebtors.Debtor)sender;
   JiwaFinancials.Jiwa.JiwaDebtors.Group dbGroup = debtor.Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaDebtors.Group>();
   dbGroup.Group.ReadRecord("00614AA4EC754C7AA2D1");
   dbGroup.Staff.ReadRecordByUsername("Admin");
   debtor.Groups.Add(dbGroup);
}
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests