Get the kit header from the kit component  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Get the kit header from the kit component

Postby DannyC » Wed May 04, 2016 6:02 pm

Hi,
Language VB .Net.

When I'm enumerating the sales order lines
Code: Select all
For Each lSalesOrderLine As JiwaSales.SalesOrder.SalesOrderLine In SalesOrderForm.SalesOrder.SalesOrderLines

and I encounter a kit component
Code: Select all
lSalesOrderLine.KitLineType = 2

how can I directly refer to it's header?
I know it must be something to do with lSalesOrderline.KitHeader but I can't seem to find the correct syntax.

The overall goal is to find out when a kit header item has any components on backorder, what I am trying to achieve is to set a line custom field on the header which would be set based on the component backordered quantity.

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

Re: Get the kit header from the kit component

Postby Mike.Sheen » Wed May 04, 2016 7:18 pm

DannyC wrote:how can I directly refer to it's header?
I know it must be something to do with lSalesOrderline.KitHeader but I can't seem to find the correct syntax.


The KitHeader is a pointer to the sales order line which is the component's header - that is: it is the kit header.

If lSalesOrderLine is a line of the sales order, and it is a component then lSalesOrderline.KitHeader.PartNo would be the PartNo of the kit header. Likewise, you can access all other properties including custom fields from that.
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: Get the kit header from the kit component

Postby DannyC » Mon May 08, 2017 1:37 pm

I know this is a year since opening this thread, but I never really got it working & am revisiting it again for another client.

So the goal is to fully backorder a kit. Without any better knowledge on how to do it, I have a custom field on the SO grid which the user can enter in a Kit Backorder qty.
Ideally the plugin should then run through the components & set them all to backordered.

I've attached the plugin as it is at the moment.
I'm getting an error which I'm stuck on. "Object reference not set to an instance of an object" but I can't work out which line is erroring.

I am also not sure if I am making this too complicated than what it should be. To get the inventory kit components, I am reading the inventory object of the kit header, then reading the inventory object of the kit component and multiplying the component qty by the custom field value. I have an inkling that there might be a better way.

I'd appreciate it if you could take a look at the plugin attached & let me know i) if there's a better way ii) what is causing the error.
Attachments
Plugin Att_Backordered Kits.xml
(37.18 KiB) Downloaded 117 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Get the kit header from the kit component  Topic is solved

Postby Mike.Sheen » Mon May 08, 2017 6:23 pm

You're getting the error because you're declaring an Inventory business logic and not actually initialising it before trying to invoke the Read method. When .Read is called InventoryObject is actually nothing - which explains your error.

Change:
Code: Select all
Dim InventoryObject As JiwaFinancials.Jiwa.JiwaInventory.Inventory
InventoryObject.Read(item.InventoryID)


To:
Code: Select all
Dim InventoryObject As JiwaFinancials.Jiwa.JiwaInventory.Inventory = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaInventory.Inventory)(Nothing)
InventoryObject.Read(item.InventoryID)


Note that I've used a factory to create it, but you could have simply done
Code: Select all
Dim InventoryObject As New JiwaFinancials.Jiwa.JiwaInventory.Inventory

I do recommend the factory method, however.

And yes - I think this is a little over-complicated for what you're trying to do - I replaced your KitBO_LineChanged with the following, and it was then correctly setting the component backorder values - no need to read the entire inventory item in for the kit header:
Code: Select all
Sub KitBO_LineChanged (item As JiwaSales.SalesOrder.SalesOrderLine, CustFieldValue As JiwaApplication.CustomFields.CustomFieldValue)
   Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(item.SalesOrderLines.SalesOrder.Client, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
   
   If item.KitLineType = JiwaSales.SalesOrder.SalesOrder.SalesOrderKitLineTypes.e_SalesOrderKitHeader Then
      If Integer.Parse(item.CustomFieldValues.ItemFromSettingName("KitBO").Contents) > 0 Then
         For Each kitComponent As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine In item.SalesOrderLines
            If kitComponent.KitHeader IsNot Nothing AndAlso kitComponent.KitHeader.Equals(item) Then
               kitComponent.QuantityBackOrdered = (kitComponent.KitUnits * Integer.Parse(item.CustomFieldValues.ItemFromSettingName("KitBO").Contents))
            End If
         Next
      End If   
   End If   
End Sub
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 16 guests