Add default inventory group if non exists  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Add default inventory group if non exists

Postby DannyC » Wed Feb 18, 2015 3:37 pm

Hi,

when saving an inventory, I want to check if the item has at least 1 Inventory Group. If not, then add in a default group.

I am just having trouble on the Add. I don't think it likes the "ZZZZZZZZZZ0000000000"

Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim InventoryForm As JiwaInventoryUI.InventoryMaintenanceForm = DirectCast(JiwaForm, JiwaInventoryUI.InventoryMaintenanceForm)
      AddHandler InventoryForm.Inventory.SaveStart, AddressOf CheckGroup
   End Sub
   
      Sub CheckGroup(Sender As Object, e As System.EventArgs)
         Dim inventory As JiwaInventory.Inventory  = DirectCast(sender, JiwaInventory.Inventory)   
         If inventory.Groups.Count <= 0  Then
            inventory.Groups.Add("ZZZZZZZZZZ0000000000")  'this bit here isn't working
         End If   
      End Sub   


Cheers

Danny
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Add default inventory group if non exists  Topic is solved

Postby Mike.Sheen » Sun Feb 22, 2015 11:07 am

Hi Danny,

Try this:

Code: Select all
Sub CheckGroup(Sender As Object, e As System.EventArgs)
   Dim inventory As JiwaInventory.Inventory  = DirectCast(sender, JiwaInventory.Inventory)   
   If inventory.Groups.Count <= 0  Then
      Dim newGroupMember As New JiwaInventory.Group
      newGroupMember.Group.ReadRecord("ZZZZZZZZZZ0000000000")
      inventory.Groups.Add(newGroupMember)
   End If   
End Sub


The Add method requires a Group object to be provided, which is actually a group member or group link object - one of its properties is the Group entity - so you need to create the group member, read the group entity of the group object (confusing naming - I know) using the ReadRecord, then add it to the inventory Groups collection. Note rather than using the ID, you can also use newGroupMember.Group.ReadRecordFromDescription("Default Group Name") - which probably will make your code more maintainable in the future.

Mike
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 7 guests

cron