Page 1 of 1

Get the kit header from the kit component

PostPosted: Wed May 04, 2016 6:02 pm
by DannyC
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

Re: Get the kit header from the kit component

PostPosted: Wed May 04, 2016 7:18 pm
by Mike.Sheen
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.

Re: Get the kit header from the kit component

PostPosted: Mon May 08, 2017 1:37 pm
by DannyC
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.

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

PostPosted: Mon May 08, 2017 6:23 pm
by Mike.Sheen
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