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"

Parents
  • Not sure if Sage City ate a post or what happened.  But I thought I said Thanks to David Speck  in an earlier reply, in fact when he posted the correction to the SetBrowseFilter I thought it was in response to my reply thanking him when I went over his suggestions.

    This script was just a test for me to get more familiar with Scripting and Sage (both of which I am a total novice at), so although the CI_Item.TotalQuantityOnHand field may be a perfect answer for getting Qty On Hand to populate on UDFs, it isn't what I am really building the script for.  The Script will actually need to interact with the Multi-Bin module from Scanco.

    I will return back with a "Last Error Message" once I update the script to filter for oSession.Updating because I am still interested in figuring out how I can get a script to execute as soon as an Item is Selected or changed by the "First, Previous, Next, Last" buttons in the Dmain Panel for Item Maintenance.

  • 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.

Reply Children
  • 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.