on 06-21-2007 1:46 PM
Good Morning
Experts:
I am having some difficulty with using the SAPbobsCOM.BoObjectTypes.oUserFields object. I have several tables that are getting built in code that use this object. However, my latest attempt to add 1 tables is causing some trouble. I am getting a -5002 Invalid Type error returned and cannot figure out why. One might think...there is an Invalid Type.
<b>In my code I add a this field and it gets added to the table structure:</b>
'***********************
'Define Field Properties
'***********************
lRetCode = 0
oUserFieldsMD.TableName = sTableNameColl(lloop)
oUserFieldsMD.Name = "DocNum" oUserFieldsMD.Description = "Purch Req#" oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Numeric
oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
oUserFieldsMD.EditSize = 10
'*****************************
'Adding the Field to the Table
'*****************************
lRetCode += oUserFieldsMD.Add
'****************
'Check for errors
'****************
If lRetCode <> 0 Then
g_B1Connection.Company.GetLastError(lErrCode, sErrMsg)
Throw New ApplicationException("AddUserField - Add Field: " & oUserFieldsMD.Name & " to Table: " & sTableNameColl(lloop) & " Failed ")
Else
UpdateStatus("Field: " & oUserFieldsMD.Name & " was Added Successfully to " & oUserFieldsMD.TableName, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
End If
<b>Later on in the code after adding more tables, I try to add this field:</b>
'***********************
'Define Field Properties
'***********************
lRetCode = 0
oUserFieldsMD.TableName = sTableNameColl(lloop)
oUserFieldsMD.Name = "WONum" oUserFieldsMD.Description = "WorkOrder"
oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Numeric
oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
oUserFieldsMD.EditSize = 10
'*****************************
'Adding the Field to the Table
'*****************************
lRetCode += oUserFieldsMD.Add
'****************
'Check for errors
'****************
If lRetCode <> 0 Then
g_B1Connection.Company.GetLastError(lErrCode, sErrMsg)
Throw New ApplicationException("AddUserField - Add Field: " & oUserFieldsMD.Name & " to Table: " & sTableNameColl(lloop) & " Failed ")
Else
UpdateStatus("Field: " & oUserFieldsMD.Name & " was Added Successfully to " & oUserFieldsMD.TableName, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
End If
I get the -5002 error. Fields are added between these 2 but none of them are of Numeric type. So, not being able to see what was wrong, I copied the last working field add for the Numeric type which is the first one listed above and changed the field name/description. Still no good.
Perhaps someone has received this same error and can shed some insight.
I appreciate the help,
Ed
Hi Ed
Try using the following code when testing for error.
If .Add() <> 0 Then
Me.msboCompany.GetLastError(mintErrNumber, mstrErrMsgm)
Select Case mintErrNumber
Case -2035, -5002 'This entry already exists / There are values in the table
'do nothing
Case Else
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserObjectPRP)
oUserObjectPRP = Nothing
Return False
End Select
End If
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well , to illustrate you could have something like this ...
oUserFields = Me.msboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields) ' oUserFields = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
With oserFields
If Not .GetByKey("FIELDK1", 0) Then
.TableName = "TABLE1"
.Name = "Field!"
.Description = "Field 1"
.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
.EditSize = CInt(arrayFields(i).DataSize)
End If
For j As Int16 = 0 To arrayFields(i).ValueList.GetUpperBound(0) - 1
Dim arrTemp() As String = Split(arrayFields(i).ValueList(j), ";")
.ValidValues.Value = arrTemp(0)
.ValidValues.Description = arrTemp(1)
.ValidValues.Add()
Next
.DefaultValue = "Value1"
Next
If .Add <> 0 Then ' check for errors
Me.msboCompany.GetLastError(mintErrNumber, mstrErrMsgm)
Me.msboApplication.StatusBar.SetText(mstrErrMsgm, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
If mintErrNumber = -2035 Then
'do nothing
Else System.Runtime.InteropServices.Marshal.ReleaseComObject(oPRPUserFields)
oPRPUserFields = Nothing
GC.Collect() 'release handle to User Fields
Return False
End If System.Runtime.InteropServices.Marshal.ReleaseComObject(oPRPUserFields)
End If
End If
End With
Notice I use an array to load the valid values. You could do so or do it one by one.
HI Ed,
Please remember to give points to the poeple who help you out - as a small recognition of their efforts... - that eventually pays off in further rewards from SDN...
...also remember to mark a thread as answered by either giving 10 points (automatically) or by (I think) going back to your original post and mark it as answered there.
Thx,
Frank
Thanks for reminding me Frank. Neftali has been a big help as I am realitvely new to some of the more "specialized" coding with the SAP objects. I was sidetracked here at the office and did not reward the points right away as I normally do. I appreciate your contact to remind me of the oversight.
Ed
No worries, Ed.
Just now and then I remember to remind people to give points - and I felt that I remembered that I had seen you giving points..., but I think it is sometimes helpful for new people to find it explicitly written somewhere when they are searching for answers and stumble over such remarks... - and so I added the reminder after you had praised Neftali soooo much
Thx,
Frank
User | Count |
---|---|
96 | |
10 | |
9 | |
5 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.