Can't figure out Event hook

I have a script for Item Maintenance that is connecting to Item Warehouse, summing up QtyOnHand and then writing it to a UDF on the Main Panel.  The script works when I can get it to run, but I am having trouble figuring out which Event I can associate the script to so it will run correctly.

When I tried launching the script with CI_Item Master on Event Table Post-Read, something "errors" and the Item Selected won't load.  Instead once I select an Item I just get a blank PMain table and the options to Accept, Delete, and Cancel become available.  It seems to me like this is where I should have the scripted launched from, but since the table field are all showing up blank, clearly my script is causing an issue here.

When I tried to hook it to use the customizer selection for the PMain panel for Inventory Management -> Item Maintenance on the trigger Event Panel - PostLoad the script works fine, but it doesn't load at the same time that the item is first selected.  I have to switch to any other tab and then back to Main to get the Script to run.

What I would like to do, is have the script run as soon as an Item is Selected or changed by the "First, Previous, Next, Last" buttons on the Dmain Panel and see my UDF field get populated at the same time as all the details on Pmain Panel get loaded.  It seems like this shouldn't be that hard, but I have 0 experience with Sage and very little with scripting.

Thanks in Advance

Script Below since it may be the reason for a blank table

oIW = 0
retvalue = 0
strStagedINV = ""
strFilterIC = ""
TotUnits = 0
OnHandUnits = 0
strItemCode=""
oIWLines=""

'''''''''''''
'Get Item Code
retvalue = oBusObj.GetValue("ItemCode",strItemCode)
'retvalue = oScript.DebugPrint("Got To Here " & strItemCode)

'''''Get ItemWarehouse as Business Object
oIW = oSession.GetObject("IM_ItemWarehouse_bus")
if oIW <> 0 then
SET oIW = oSession.AsObject(oIW)
' retvalue = oScript.DebugPrint("Got Inside the oIW")
end if
'retvalue = oScript.DebugPrint("oIW should be loaded")

'''''''Establish ItemCode as Search Term for ItemWarehouse
retvalue = oIW.SetBrowseIndex(Itemcode, "")
retvalue = oIW.SetBrowseFilter(ItemCode & "" & strItemCode)

'''''Cycle through Warehouse for Item summing totals

retvalue = oIW.MoveFirst()
while not (cBool(oIW.EOF))
retvalue = oIW.GetValues("ItemCode,WarehouseCode,BinLocation,QuantityOnHand,QuantityOnPurchaseOrder,QuantityOnSalesOrder",oIWLines)
' retvalue = oScript.DebugPrint(oIWLines)
retvalue = oIW.GetValue("QuantityOnHand",OnHandUnits)
retvalue = oIW.GetValue("ItemCode",strFilterIC)
'Had to add an If statement, because the filter is returning items that contain strItemCode instead of = to
if (strItemCode = strFilterIC) then
TotUnits = TotUnits + OnHandUnits
end if
' retvalue = oScript.DebugPrint(OnHandUnits & " " & TotUnits)
oIW.MoveNext
wend

'retvalue = oScript.DebugPrint("On Hand " & OnHandUnits & " Total " & TotUnits)
strStagedINV = TotUnits
retvalue = oBusObj.SetValue("UDF_STAGEDINV",strStagedINV)
oBusObj.Write()
'msgbox "Reached Script End"

  • in reply to ifitworksitsgood

    Good luck using scripts with ScanCo (or any 3rd party enhancement).  Those business objects are undocumented and may not have scripting fully enabled.

  • in reply to ifitworksitsgood

    Post-Read on the CI_Item table and a UI Post-Load on the pMain panel (or which ever panel that you add your UDF to) of Item Inquiry/Maintenance should do the trick.  You will need to test if the oScript.UIObj property is not equal to zero to make sure you are in a UI task and then after getting the object handle set, use GetScreenName to check that the script is executing on the IM_Item.m4l library.  You can additionally filter for the oSession.Updating being equal to 0 but if you are already filtering on the screen name, i don't think this will make much of a difference but it is a good habit to be aware of.

    You can also use the UI object's SetControlProperty to set the "Value$" property of your UDF to the value returned after reading IM_ItemWarehouse, this will avoid causing the business object to think you modified the record and prompt to save it.

  • in reply to Kevin M

    Yea...working with third party objects is not fun, it can be hit or miss but worth trying I suppose.  As long as you are doing simple things like reading a record, I would expect most objects at this point to at least have a *_svc or *_bus version of it and support the basic methods that would be inherited by SY_Service but I still occasionally run across stuff that doesn't.

  • FormerMember
    FormerMember in reply to Kevin M

    Excellent point Kevin. Not all 3rd party providers feel obligated to extend their modifications  through scripting.