Before going live on CSI, we had an Infor consultant write a script for us to calculate the UPC code for new finished goods.
This should essentially do a look up in the SLItems IDO for the largest value in the itemUf_jcm_UPCkey column and add 1 to it to calculate the next UPC Key -- which is then combined with our unique UPC Prefix to generate the new UPC code.
The problem is that the script is not getting the maximum value from the itemUf_jcm_UPCkey field. Instead, it appears they are just sorting the field and getting the first column value from descending order. Below is the script - can anyone offer advice on changing this to get the largest value?
Sub QueryItem()
'ICS001 - Provided code for this Sub 05.31.2017.
'
Dim vNextUpc As Integer
Dim oUpdReq As New Mongoose.IDO.Protocol.UpdateCollectionRequestData("SLItems")
Dim oUpdRes As New Mongoose.IDO.Protocol.UpdateCollectionResponseData
Dim oResp As LoadCollectionResponseData
Dim sProps As String = "itmUf_jcm_UPCKey"
Dim sFilter As String = "1=1" 'DH "itmUf_jcm_UPCKey is not null"
Try
oResp = IDOClient.LoadCollection("SLItems", sProps, sFilter, "itmUf_jcm_UPCKey desc", 1)
If oResp.Items.Count > 0 Then 'if item record exists
'Application.ShowMessage(oResp.Item(0, "itmUf_jcm_UPCKey").ToString)
If oResp.Item(0, "itmUf_jcm_UPCKey").ToString = "" Then
vNextUpc = 26000
ThisForm.Components("UPCKeyEdit").Value = vNextUpc.ToString
'Application.ShowMessage(ThisForm.Components("UPCKeyEdit").Value)
Else
Dim vUPC As String
Dim vUPC_Num As Integer
vUPC = oResp.Item(0, "itmUf_jcm_UPCKey").ToString
vUPC_Num = CInt(vUPC) + 1
If vUPC_Num < 10 Then
ThisForm.Components("UPCKeyEdit").Value = "0000" & vUPC_Num.ToString 'oResp.Item(0,"itmUf_jcm_UPCKey").ToString
Else
If vUPC_Num > 9 And vUPC_Num < 100 Then
ThisForm.Components("UPCKeyEdit").Value = "000" & vUPC_Num.ToString
Else
If vUPC_Num > 99 And vUPC_Num < 1000 Then
ThisForm.Components("UPCKeyEdit").Value = "00" & vUPC_Num.ToString
Else
If vUPC_Num > 999 And vUPC_Num < 10000 Then
ThisForm.Components("UPCKeyEdit").Value = "0" & vUPC_Num.ToString
Else
If vUPC_Num > 9999 And vUPC_Num < 99999 Then
ThisForm.Components("UPCKeyEdit").Value = vUPC_Num.ToString
Else
Application.ShowMessage("Next Up number has exceeded 99999. Time to replace the upc prefix. Update Variable JCM_UPCPrefix with new Prefix")
ThisForm.Components("UPCKeyEdit").Value = ""
End If
End If
End If
End If
End If
'application.ShowMessage(ThisForm.Components("UPCKeyEdit").Value)
End If
ThisForm.Components("UPCEdit").Value = ThisForm.Variables("JCM_UPCPrefix").Value & ThisForm.Components("UPCKeyEdit").Value
UpdateUPCCode()
Else
'default value for the nextupckey = 1
Dim vUPC As String
Dim vUPC_Num As Integer
vUPC = oResp.Item(0, "itmUf_jcm_UPCKey").ToString
vUPC_Num = CInt(vUPC) + 1
If vUPC_Num < 10 Then
ThisForm.Components("UPCKeyEdit").Value = "0000" & vUPC_Num.ToString 'oResp.Item(0,"itmUf_jcm_UPCKey").ToString
Else
If vUPC_Num > 9 And vUPC_Num < 100 Then
ThisForm.Components("UPCKeyEdit").Value = "000" & vUPC_Num.ToString
Else
If vUPC_Num > 99 And vUPC_Num < 1000 Then
ThisForm.Components("UPCKeyEdit").Value = "00" & vUPC_Num.ToString
Else
If vUPC_Num > 999 And vUPC_Num < 10000 Then
ThisForm.Components("UPCKeyEdit").Value = "0" & vUPC_Num.ToString
Else
If vUPC_Num > 9999 And vUPC_Num < 99999 Then
ThisForm.Components("UPCKeyEdit").Value = vUPC_Num.ToString
Else
Application.ShowMessage("Next Up number has exceeded 99999. Time to replace the upc prefix. Update Variable JCM_UPCPrefix with new Prefix")
ThisForm.Components("UPCKeyEdit").Value = ""
End If
End If
End If
End If
End If
'application.ShowMessage(ThisForm.Components("UPCKeyEdit").Value)
ThisForm.Components("UPCEdit").Value = ThisForm.Variables("JCM_UPCPrefix").Value & ThisForm.Components("UPCKeyEdit").Value
UpdateUPCCode()
End If
Catch ex As Exception
Application.ShowMessage("exception : " + ex.Message)
End Try
End Sub