Kit Components Table Pre-Write

I have a simple table pre-write to populate an UDF_QTY_PULLED column based on the order qty, if the line is a kit component.  I ran into a problem when we have to go and adjust the UDF manually, the script keeps on firing to change the UDF back to the order qty.  Trying to figure out how I can change the UDF and not have the script fire.  When we need to manually adjust we have to set the BO Qty to the amount we are missing from inventory and make the udf 99% of the time 0, and also populate the vendor no. field.  The kit explodes and there is no vendor no in that field so I thought I could try to use that trigger.

If oSession.CompanyCode = "TST" then

rVal = 0
nOrdered = 0
sKit = ""
sVend = ""


rVal = oBusObj.GetValue("SkipPrintCompLine$", sKit)
rVal = oBusObj.GetValue("QuantityOrdered", nOrdered)

if sKit = "Y" then

'rVal = oBusObj.GetValue("QuantityOrdered", nOrdered)
'rVal = oBusObj.GetValue("VendorNo$", sVend)

'if nOrdered <> 0 then

rVal = oBusObj.SetValue("UDF_QTY_PULLED", nOrdered)

if sVend <> "" then

rVal = oBusObj.SetValue("UDF_QTY_PULLED", 0)


end if
end if
end if

  • 0

    Not sure if this is the best way but, solved my issue by having a script on a table pre write SO_Details and then another script column post val on the BO qty.  Both scripts below.

    rVal = 0
    nOrdered = 0
    sKit = ""
    sVend = ""
    
    
    rVal = oBusObj.GetValue("SkipPrintCompLine$", sKit)
    rVal = oBusObj.GetValue("QuantityOrdered", nOrdered)
    rVal = oBusObj.GetValue("VendorNo$", sVend)
    
    if sKit = "Y" and sVend = "" then
    
    rVal = oBusObj.SetValue("UDF_QTY_PULLED", nOrdered)
    
    
    end if

    rVal = 0
    nOrdered = 0
    nBO = 0
    sKit = ""
    sVend = ""
    
    
    rVal = oBusObj.GetValue("SkipPrintCompLine$", sKit)
    rVal = oBusObj.GetValue("QuantityBackordered",nBO)
    
    if sKit = "Y" and nBO <> 0 then
    
    rVal = oBusObj.SetValue("UDF_QTY_PULLED", 0)
    
    end if

  • 0 in reply to jland47

    In a line script, you can use oHeaderObj.GetValue to access header fields like OrderType.  That would allow you to configure conditional logic, applied to Backorders (...OrderType = B).

  • 0 in reply to Kevin M

    We are not using the BO qty field like it should be, so a SO could have a BO qty and the order type still be =S.

  • 0 in reply to jland47

    Then build your condition on whether the QtyBO is non-zero?

    The column script fires before the pre-write, so I'd think it would be possible to build everything into the pre-write... but if you have something working, there is no need to change it.

  • 0 in reply to Kevin M

    I thought I had something, scripts work when manually entering the kits and they explode, had orders import in this morning and the scripts didn't fire.  I can't seem to get any scripts to fire on kit component lines when imported, I've tried table-prewrite, table post-write, column post val on qty ordered.  Started thinking the actual kit item does not have any OH inventory so when the line imports it put a qty in the BO qty field on the kit item, then when it explodes all the components get the BO qty populated just like the actual kit item code.  The function to BO if an item is not in stock is a SAGE function, could by script to ignore that function if the item is a kit item code?  Maybe that would work on the imported lines?

  • 0 in reply to jland47

    Some Sage programming bypasses certain script events, and it looks like you found one. 

    When that happens to me, I consider a different approach (like a header PreTotals script that loops through lines, with all the script conditions / logic there... being careful to avoid an endless recursion issue).

  • 0 in reply to Kevin M

    I got a pretotal to work but it seems like another pretotal script I have on the SOH is not getting triggered due to either this pretotal or it does not like the kit component lines.

  • 0 in reply to Kevin M

    Didn't finish my thought, we are exploding the kit when the line is entered, is it possible to not automatically explode the kit on the lines and only explode it on the "pick sheet"?

  • 0 in reply to jland47

    Exploding the kit components in the SO determines how inventory is depleted.  Explode: component inventory is depleted during shipping.  Don't explode: the parent item's inventory is depleted.  You can do a sub-report on a form to print a recipe for the parent item (without exploding the kit) but that won't change how inventory is consumed during shipping.

    For multiple scripts on the same event, make sure each one uses a distinct Priority value, otherwise they merge when compiled... which can be bad.

  • 0 in reply to Kevin M

    Yes, aware of the priority issues due to previous experiences.  Could you glaze over both of these scripts (both on table-pre-total) to see if anything stands out, I put the "SOH_KIT" script on priority 500 to run first then the "allocate" script on 600.  The "SOH_KIT" script runs for the kit lines, however I can't get the allocate script to run initially, if I make some edits to the lines and go back it will fire off. I am not positive on the SOH_KIT script, I feel like it is missing something because it runs every time I tab over the lines tab to totals in the debug environment.  In DFDM my udf's equal the udf for line totals so the second script is true (component lines trigger udf's) just not firing.

    If oSession.CompanyCode = "TST" and oBusObj.EditState = 2then
    r=oScript.DebugPrint("COMPANY:" & oSession.CompanyCode)
    r=oScript.DebugPrint("EDIT STATE:" & oBusObj.EditState)
    rVal = 0
    nOrdered = 0
    sKit = ""
    nBO = 0
    
    	Set oLines = oSession.AsObject(oBusObj.Lines)
    	r=oScript.DebugPrint("After oSession.GetObj")
    		
    	rVal = oLines.MoveFirst()
    	Do Until cBool(oLines.EOF) 'Keep looping until record pointer is on last line
    
    	rVal = oLines.GetValue("SkipPrintCompLine$", sKit)
    	rVal = oLines.GetValue("QuantityOrdered", nOrdered)
    	rVal = oLines.GetValue("QuantityBackordered", nBO)
    	r=oScript.DebugPrint("Component: " & sKit)
    	r=oScript.DebugPrint("QuantityOrdered:" & nOrdered)
    	r=oScript.DebugPrint("QuantityBackordered:" & nBO)
    			
    		if sKit = "Y" and nBO = 0 then
    
    		rVal = oLines.SetValue("UDF_QTY_PULLED", nOrdered)
    		rVal = oLines.Write()
    		r=oScript.DebugPrint("rVal on oLines Write: " & CStr(rVal))
    
    		
    		end if
    	rVal = oLines.MoveNext()
    	Loop
    end if

    rVal = 0
    nRec = 0
    nPull = 0
    nUnits = 0
    nTotal = 0
    sType = ""
    dToday = ""
    
    rVal = oBusObj.GetValue("OrderType$", sType)
    
    if sType = "S" Or sType = "B" then
    
    rVal = oBusObj.GetValue("UDF_TOTAL_QTY_REC", nRec)
    rVal = oBusObj.GetValue("UDF_TOTAL_QTY_PULLED", nPull)
    rVal = oBusObj.GetValue("UDF_UNIT_COUNT", nUnits)
    
    nTotal = nRec+nPull
    
    	if nTotal = nUnits then
    
    	rVal = oBusObj.SetValue("UDF_ALLOCATED$", "Y")
    	rVal = oSession.FormatDate(oSession.SystemDate, dToday, "%M/%D/%Y")
    	
    	dToday = oSession.GetFormattedDate(CStr(dToday))	
    
    	rVal = oBusObj.SetValue("UDF_DATE_ALLOCATED$", dToday)
    
    	end if
    
    end if