Hi All,
Thanks for all the suggestion but still no luck on the conditional setting of the UPC. In the end, I do not thing it will be a big issue for the client, but my concern was/is that someone could make a type on the Cat1 field that would require the UPC to be updated.
I left out that is a post validate on Cat1. Even tried changing it table pre write but it did not change the outcome.
Alnoor, I love the idea of case statements but for what ever reason they never work for me. Even using yours exactly would not pass syntax test (syntax is the bane of my existence in scripting as I don't do it enough to really "get it" well enough)
Dan, the company code condition is because this UPC code only applies to this company. Others have a different code. What I was trying to do was set a condition to have it wipe out the UPC entry if the Cat1 field was empty rather than just write the prefix of the UPC.
I tried two if statements and the len test still did not seem to work, in spite of trying the different ideas on testing the length.
So went with a "single" pass script for now - it works but does not, for what ever reason, update the UPC if the cat1 is changed. .
'Generate UPC No
'Bob Osborn ACI
sUPC = "" : sCat1 = ""
if oSession.CompanyCode = "ATP" then
RetVal = oBusObj.GetValue("Category1$",sCat1)
sUPC = "799158" & sCAt1
SMsg = sUPC
' rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
RetVal = oBusObj.SetValue("UDF_UPC$", sUPC)
end if ' Company Code
------------------------------
Bob Osborn
Consultant
ACI Consulting
------------------------------
Original Message:
Sent: 01-28-2021 12:53
From: Alnoor Cassim
Subject: Seemingly simple question
Bob - I assume script is running on Post-Val of Cat1. You could rearrange it like this where you're checking the Length and checking if an error occurred:
sUPC = "" : sCat1 = ""
If oSession.CompanyCode = "ATP" then
sCat1 = value
nLen = Len(sCat1)
sMsg = "Cat1 = " & sCat1 & " Length of Cat1 = " & nLen
rMsg=oSession.AsObject(oSession.UI).MessageBox("",sMsg)
Select Case nLen
Case 0
rV = oBusObj.SetValue("UDF_UPC$", "")
If rV <= 0 Then
'0 is an error and -1 is a warning
sMsg = "SetValue of UPC from blank Cat1 = " & rV & vbCrLf & oBusObj.LastErrorMsg
Else
sMsg = "SetValue of UPC from blank Cat1 successful"
End If
rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
Case > 0
sUPC = "799158" & sCat1
rV = oBusObj.SetValue("UDF_UPC$", sUPC)
'Just in case
If rV <= 0 Then
sMsg = "Last Error/Warning on SetValue of " & sUPC & _
" to " & sCat1 & " = " & oBusObj.LastErrorMsg
rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
End If
Case Else
'Drop thru
End Select
End If 'check for CompanyCode
------------------------------
Alnoor Cassim
Email: alnoor@asifocus.com
Ph: 949-689-9887
Orange County, CA
------------------------------