Script to retrieve primary vendor alias

SOLVED

I'm new to scripting and having a little trouble.  I'm trying to grab the primary vendor alias for an item from IM_AliasItem and put it into a UDF in CI_Item.  This will probably be triggered on reading the item record, if that makes a difference, but I have it on a button right now for testing.  The problem seems to be that because I am searching for a record with a partial key (i.e., I only have the record type, division, vendor, and item code, but not the alias itself) I am using SetBrowseFilter, but maybe I am not formatting it correctly.  If I only search with the "Type/Division/Vendor" part of the key I get a result (the first record that matches that vendor - not what I'm looking for), but when I add the Item Code to the end I get no result.  Here is my script:

'by PLW 6/26/18
'To write the primary vendor alias from IM_AliasItem into CI_Item UDF
retVal = 0
sPVendor = ""
sItemCode = ""
sDiv = ""
sAlias = ""
sPVAlias = ""

'retrieve the CI_Item info
retVal = oBusObj.GetValue("PrimaryVendorNo$", sPVendor)
retVal = oBusObj.GetValue("ItemCode$", sItemCode)
retVal = oBusObj.GetValue("APDivisionNo$", sDiv)

'bring in the IM_AliasItem table and search for the primary vendor alias
set oAliasItem = oSession.AsObject(oSession.GetObject("IM_AliasItem_bus"))
retVal = oAliasItem.SetBrowseIndex("KVENDORITEM","")
retVal = oAliasItem.SetBrowseFilter("V" & sDiv & sPVendor & sItemCode) <<<< when I add this, I get no result
retVal = oAliasItem.MoveNext()

'diagnostic message box
'sMsg = cstr(retVal) + " - " + oAliasItem.LastErrorMsg
'retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)

'assign the primary vendor code if found
    If retVal = 1 then
        retVal = oAliasItem.GetValue("AliasItemNo$", sPVAlias)
    End If

'write to the UDF
retVal = oBusObj.SetValue("UDF_PR_VND_ITM_AL$", sPVAlias)

Any help would be greatly appreciated!

  • +1
    verified answer

    Multi-part keys need to be padded so each value fills the full size of that part of the key.  (Your script may work with a VendorNo with all digits used).  Here's an example from a lookup I use with IM_ItemWarehouse:

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

  • 0 in reply to Kevin M

    That did the trick.  I was tripped up by the division, since retVal = oBusObj.GetValue("APDivisionNo$", sDiv) was apparently returning null instead of 00.  We don't use divisions right now, but instead of hard-coding it I did

    If sDiv = "" Then sDiv = "00" End If

    and put the padding on it as well, for future-proofing.

    Thanks for your help!

    Paul