IM_ItemCost

SOLVED

I'm trying to find the last unit cost for a warehouse in Sales Order entry.  Sage defaults to the last unit cost for all warehouses.  I'm getting a not found from this code.  I don't know the GROUPSORT.

If oSession.CompanyCode = "TST" Then
retval = oSession.AsObject(oSession.UI).Messagebox( "","Pre Write SO_Last_Warehouse_Cost Script")
'************* ITEM COST & COST**************
ItemCode = ""
StdCost = 0
ItemType = ""

Cost_Type =""


Warehouse = ""

retval = oHeaderObj.GetValue("OrderType$",OrderType)

retval = oBusObj.GetValue("ItemCode$",ItemCode)
retval = oBusObj.GetValue("WarehouseCode$",Warehouse)
retval = oBusObj.GetValue("UnitCost",StdCost)
retval = oSession.AsObject(oSession.UI).Messagebox( "","Key=" & itemcode & warehouse)

'*** ITEM WAREHOUSE COST ***

oItemCode = oSession.GetObject("IM_ItemCost_bus")

if oItemCode <> 0 then
 Set oItemCode = oSession.AsObject(oItemCode)
else
 retval = oSession.AsObject(oSession.UI).Messagebox( "","oItemCode failed")
 return
end if
 
retval = oItemCode.SetKeyValue("ItemCode$",ItemCode)
retval = oItemCode.SetKeyValue("WarehouseCode$",Warehouse)
retval = oItemCode.SetKeyValue("TierType$","1")
retVal = oItemCode.SetKey()

'if 1 then Item was found
if retVal = 1 then
retval = oSession.AsObject(oSession.UI).Messagebox( "","Warehouse Item Cost Found")
else
 retval = oSession.AsObject(oSession.UI).Messagebox( "","Warehouse Item Cost Not Found")
end if
 retval = oSession.DropObject("IM_ItemCost_bus")
end if

  • 0

    Try SetBrowseFilter and MoveFirst, MoveNext... This allows you to filter a table and loop through a subset of records without a full key.

  • +1 in reply to Kevin M
    verified answer

    Where do I use the SetBrowserFilter?  Would it be retVal = oItemCode.SetBrowserFilter() rather than retVal = oItemCode.SetKey()

  • 0 in reply to Kevin M

    I finally got it to work.  Thank you.  Here is the final result.

    If oSession.CompanyCode = "TST" Then
    'retval = oSession.AsObject(oSession.UI).Messagebox( "","Post Qty Ordered SO_Last_Warehouse_Cost Script")
    '************* ITEM COST & COST**************
    ItemCode = ""
    Spaces = "                              "
    StdCost = 0
    WarehouseCode = ""
    TierType ="1"
    One = "1"
    GroupSort = "2019"
    LastCost = 0
    ItemCodeTmp = ""
    WarehouseTmp = ""
    GroupSortTmp = ""
    ItemcodeTest = ""
    count = 1
    retval = oBusObj.GetValue("ItemCode$",ItemCode)
    retval = oBusObj.GetValue("WarehouseCode$",WarehouseCode)
    retval = oBusObj.GetValue("UnitCost",StdCost)
    ItemCode = left(Itemcode+Spaces,30)
    'retval = oSession.AsObject(oSession.UI).Messagebox( "","Key=" & itemcode & warehousecode)
    '*** ITEM WAREHOUSE COST ***
    oItemCode = oSession.GetObject("IM_ItemCost_bus")
    if oItemCode <> 0 then
     Set oItemCode = oSession.AsObject(oItemCode)
    else
     retval = oSession.AsObject(oSession.UI).Messagebox( "","oItemCode failed")
     return
    end if

    retVal = oItemcode.SetBrowseIndex("KINVERSEDATE","")
    retVal = oItemCode.SetBrowseFilter(ItemCode+WarehouseCode+TierType)

    'if 1 then Item was found
    if retVal = 1 then
    'retval = oSession.AsObject(oSession.UI).Messagebox( "","Warehouse Item Cost Found")
    retVal = oItemcode.MoveFirst()
     retval = oItemcode.GetValue("ItemCode$",ItemCodeTmp)
     retval = oItemcode.GetValue("WarehouseCode$",WarehouseTmp)
     retval = oItemcode.GetValue("GroupSort$",GroupSortTmp)
     retval = oItemcode.GetValue("UnitCost",LastCost)
    'retval = oSession.AsObject(oSession.UI).Messagebox( "","Key=" & ItemCode &" Item " & ItemCodeTmp & " Warehouse" & WarehouseTmp & " Sort " & GroupSortTmp & " Cost " & Lastcost & " Count " & Count)
     
      if WarehouseCode <> WarehouseTmp then
       'retval = oSession.AsObject(oSession.UI).Messagebox( "","Warehouse Item Cost Not Found")
      else
       'retval = oSession.AsObject(oSession.UI).Messagebox( "","New Cost =" & Lastcost)
       retval = oBusObj.setvalue("UnitCost",LastCost)
      end if
     
    else
     'retval = oSession.AsObject(oSession.UI).Messagebox( "","Warehouse Item Cost Not Found") 
    end if
     retval = oSession.DropObject("IM_ItemCost_bus")
    end if
  • 0 in reply to jryals
    verified answer

    Be sure you're getting correct results.  Normally I've had to pad the lookup string with chr(0)...

    PartialKey = sItemCode & String(30-Len(sItemCode),Chr(0)) & sWarehouseCode &...