Error -5002 when adding linked user defined field using DI API
Hello,
When I try to add a linked user defined field using DI API I get the error number -5002 with description:
"The field 'Related Table' should consist of 8 alphanumeric characters with no valid or default values"
I Get the error when I use the Add method.
What is the solution for this problem? I use SBO 2005 A SP1 Patch 18
The code I use is (.NET C# 2.0):
SAPbobsCOM.IUserFieldsMD uf = (SAPbobsCOM.IUserFieldsMD)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
uf.Name = "S_BUCO";
uf.TableName = "OPOR";
uf.Type = SAPbobsCOM.BoFieldTypes.db_Memo;
uf.SubType = SAPbobsCOM.BoFldSubTypes.st_Link;
uf.LinkedTable = "S_BU";
uf.Description = "Description";
uf.Add()
Regards,
Jeffrey
Hi Jeffrey,
Your code above does not match the settings you are using in the UI. In particular, the type and subtype you are setting in code are not correct.
To create the UDF via code, set the field types as follows:
SAPbobsCOM.IUserFieldsMD uf = (SAPbobsCOM.IUserFieldsMD)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
uf.Name = "S_BUCO";
uf.TableName = "OPOR";
uf.Type = SAPbobsCOM.BoFieldTypes.db_Alpha;
uf.EditSize = 8;
uf.LinkedTable = "S_BU";
uf.Description = "Description";
uf.Add()
There's no need to set the SubType property as you require a regular alphanumeric field.
Kind Regards,
Owen
Similar Messages
-
SDK Error -5002 when adding a sales order
I'm getting an error -5002 when adding a sales order.
Source code:
IDocuments m_so2 = SBOCOMUtil.newDocuments(icmp, SBOCOMConstants.BoObjectTypes_Document_oOrders);
line = m_so2.getLines();
m_so2.setCardCode("2173231916");
m_so2.setCardName("test Sales order");
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
Date today = Calendar.getInstance().getTime();
m_so2.setDocDueDate(today);
line.setItemCode("01005");
line.setDiscountPercent(new Double(10));
line.setItemDescription("description Testing");
line.setQuantity(new Double(3));
line.setTaxCode("0");
line.add();
long rc = m_so2.add();
Question:
Where can I find a list of error codes that can be easy to understand? PDF, word, etc.
Thanks.Hi Diego,
Looking at your code I see that you are doing a
line.add();
You dont need to have this here unless you are adding another line to your document.
Maybe this will help you.
Also just because java is a bit different from VB get the last error message using
SBOErrorMessage errMsg= comp.getLastError();
System.out.println(errMsg.getErrorMessage());
-Cormac -
Opening User defined Fields Form via API
Hi
Is there a posiibility to open those user defined field - forms via API. If yes is it possible to check if it is already open?
TIA
PhileHi,
In your eventhandler, you can use this:
Set oSboForm = Sbo_application.Forms.GetFormByTypeAndCount(-pval.FormType, pval.FormTypeCount)
form and udf-form are linked through a minus sign.
I do not know of a nice way to check if they are anebled. What I'm currently doing is running the above line of code contained in an error handler. The error handler does a sendkeys of control shift u (which enables the udf-form) and displays a message. Problem is after control shift u, screen is not yet updated so your code cannot continue immediatelly. Development knows of this problem, but I never received a promise when this will be fixed.
Hope this helps,
Jacques -
User defined fields via DI-API
I want to read user defined fields using the DI-API.
The following code works but lists only UDFs defined for articles:
SAPbobsCOM.Items item =
(SAPbobsCOM.Items) GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
int count = item.UserFields.Fields.Count;
MessageBox.Show("count == "+anzahl.ToString(), "OK");
for(int i=0; i<count; i++){
MessageBox.Show("index == "+i.ToString(), "OK");
MessageBox.Show("name == "+item.UserFields.Fields.Item(i).Name, "OK");
If I try to list all UDFs defined in the system using the oUserFields object I get an exception when I assign the business object:
try{
SAPbobsCOM.UserFields ufd = (SAPbobsCOM.UserFields)
GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); // exception
int count = ufd.Fields.Count;
catch(System.Exception ex){
MessageBox.Show("ex.ToString(), "OK");
The exception says something like
InvalidCastException: COM object of type 'System.__ComObject' can not casted into
interface type SAPbobsCOM.UserFields
Thank you for help,
Frank RomeniHi Vítor,
thank you for the hint to UserFieldsMD - now the access works.
You wanted to know what I am trying to do - let me explain the background even it is a bit complicated:
I have to access a certain UDF defined for articles.
To access this UDF I can't use a fixed index like e.g. '5' in
item.UserFields.Fields.Item(5).Value
because this index is 5 only on my local machine - it could be a different index on the target machine.
I solved this in writing some sql-code to access table CUFD and to find the index of this UDF in CUFD.FieldID.
But sometimes there is a problem when there are UDFs deleted from the database. It is possible that there are 'holes' between the FieldId of UDFs of one object, e.g.
Initial entries in CUFD (Table, FieldId, Name => code to access field):
OITM 0 'myUDF1' ==> item.UserFields.Fields.Item(0).Value
OITM 1 'myUDF2' ==> item.UserFields.Fields.Item(1).Value
OITM 2 'myUDF3' ==> item.UserFields.Fields.Item(2).Value
After deletion of 'myUDF2':
OITM 0 'myUDF1'
OITM 2 'myUDF3'
Now the access to 'myUDF2' with item.UserFields.Fields.Item(2).Value fails!
You have to use index '1' in .Item(index) to access 'myUDF2' because this UDF is now the second UDF in the item object (zero based).
After I realized this I didn't use the sql-code to get FieldID any longer and searched with a loop all existing indices and compared them with the name of my special UDF, e.g. (this code works as expected):
public int getUDFIndex(string udfName){
index = -1;
for(int i=0; i<item.UserFields.Fields.Count; i++{
if(item.UserFields.Fields.Item(i).Name == udfName){
index = i;
break;
return index;
Now I tried to make this method more general to find UDFs in any object - not only in item objects.
This is the background I wanted to access SAPbobsCOM.UserFields for.
The problem is that UserFieldsMD has no method like Item(index) as I used it in my example.
Do you have an idea to solve the problem with the 'holes' between FieldId in the UFD-table CUFD?
Frank Romeni -
Update User Defined Field using DBDataSource
Hi All,
I'm trying to update the user defined field using the DBDataSource object. However an error occurred - "Item is not a User-Defined Field".
The code used is as follows:
Dim oDS as SAPbouiCOM.DBDataSource
Dim oForm as SAPbouiCOM.Form
Set oForm = SBO_Application.Forms.GetForm("139", 1)
Set oDS = oForm.DataSources.DBDataSources.Item("ORDR")
oDS.SetValue("U_Field1",oDS.Offset,"abc")
Please help.If you haven´t put the field directly in the standard form the user defined fields are in a different form. This form has the same type but with "-" before it.
So so should use this code to get the user defined fields form:
Set oForm = SBO_Application.Forms.GetForm("-139", 1)
Maybe this can be the cause -
Problem Occurs when CFL is added with User defined field
form-672-BOM
item-3-datagrid
U_EmpNo - user defined field column
if i will give following codes under form load event will CFL bound with U_EmpNo
or else plz suggest me with write codes
oForm = SBO_Application.Forms.Item("672")
oItem = oForm.Items.Item("3")
oClmn = oItem.Specific
oClmns = oClmn.Item("U_EmpNo")
oClmns.DataSources.UserDataSources.Add("U_EmpNo", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
MessageBox.Show("Did")
AddChooseFromList()
oClmns.DataBind.SetBound(True, "", "U_EmpNo")
oClmns.ChooseFromListUID = "CFL1"
oClmns.ChooseFromListAlias = "CardCode"hi
-
IMPORT USER DEFINED FIELD USING DTW
Hi
I want to IMPORT USER DEFINED FIELD OF SALE ORDER THAT ARE PRESENT IN ROW LEVEL AND DOCUMENT LEVEL
USING DTW.
SO PLZ GIVE ME SOLUTION FOR THAT.
THANK YOUHi,
What is your B1 version and PL? Please do not use all CAPS. It is not polite.
Thanks,
Gordon -
Creating User Defined Fields via DI API
Hello,
Has anyone tried creating User Defined Fields via DI without direct database intervention ? My add on relies on some UDF's that have to be created on install.
Thank youI regularly use the UI API to do this. You can find several discussions on this forum. I have not put this in my installation program, but I use UserFieldsMD in the DI API and a CSV file from Excel to store the information about the fields.
-
Error while linking user defined table to user defined field using vb6.0
Hi,
I am creating a userdefined field on a SAPB1 table(PDN1) using vb 6.0
I am trying to link this field to a user defined table.
When i do that i get the following error:
"The field 'Related table' should consist of 8 alphanumeric chracters with no valid or default values"
When i try to do the same thing from SAPB1(not using code) there is no such problem.
My vb code is as follows:
Set oUserFieldsMD = oCmp.GetBusinessObject(oUserFields)
oUserFieldsMD.TableName = "PDN1"
oUserFieldsMD.Name = "OB_Locn"
oUserFieldsMD.Description = "WH Location"
oUserFieldsMD.Type = db_Alpha
oUserFieldsMD.EditSize = 30
lRetCode = oUserFieldsMD.Add
If lRetCode <> 0 Then
oCmp.GetLastError lErrCode, sErrMsg
MsgBox sErrMsg
GoTo Err_
End If
If Not oUserFieldsMD.GetByKey("PDN1", 0) Then
MsgBox "Error"
GoTo Err_
End If
oUserFieldsMD.LinkedTable = "OB_TEST"
lRetCode = oUserFieldsMD.Update
Your help will be much appreciated.
Thanks.Great Sébastien!
Looks like we could not survive here one day without your contribution
Best regards,
Frank
PS: For readers of this thread who don't understand why
EditSize
must be "8":
This is the size of the
Code
field in the user-defined table to which the new field OB_Locn (in the DB it will be U_OB_Locn) is linked to...
So, it should be preferrably of the same size. -
Error -5002 when adding a UDF, with B1 9.1
Hello,
in the past I wrote some addons for SAP B1 9.0 and worked well.
Now I just upgraded our SAP B1 32-bit client from 9.0 to 9.1.
If I try to run any of my addons and I get error code -5002, with description "Nessun record dati" ("No data records" in English).
It occures in this piece of code that creates UDFs, when doing Add() the result is -5002 instead of 0:
UserFieldsMD md = (UserFieldsMD)Global.oCompany.GetBusinessObject(BoObjectTypes.oUserFields);
string realFieldName = "U_NS_MYFIELD";
// Setting the Field's properties
md.TableName = "RDR1";
md.Name = "NS_MYFIELD";
md.Description = "My field";
md.Type = BoFieldTypes.db_Alpha;
md.SubType = BoFldSubTypes.st_None;
md.EditSize = 254;
md.Mandatory = BoYesNoEnum.tNO;
// Adding the Field to the Table
int result = md.Add();
Global.ReleaseComObject(md);
This occures both keeping the old 9.0 version of SAPbobsCOM.dll and changing it to the new 9.1 version...
Maybe the mechanism for creating UDFs has been changed? The reference (REFDI.chm) doesn't tell it.
Kind regardsThis function is how I create UDF. I'm using it since SAP 8.8
Function CreateUDF(ByVal TableName As String, ByVal FieldName As String, ByVal FieldDescription As String, Optional ByVal UDFLength As Integer = 10, Optional ByVal FieldType As SAPbobsCOM.BoFieldTypes = SAPbobsCOM.BoFieldTypes.db_Alpha, Optional ByVal DefaultValue As Object = "", Optional ByVal ShowMessage As Boolean = False, Optional ByVal dtValidValues As Data.DataTable = Nothing, Optional ByVal LinkedTable As String = "", Optional ByVal FieldSubType As SAPbobsCOM.BoFldSubTypes = Nothing, Optional ByVal isMandatory As SAPbobsCOM.BoYesNoEnum = SAPbobsCOM.BoYesNoEnum.tNO, Optional ByVal isUpdateExisting As Boolean = False) As Boolean
Try
Dim FieldID As Integer = GetUDFId(TableName, FieldName)
oRecset = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
If Not IsNothing(oRecset) Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oRecset)
oRecset = Nothing
GC.Collect()
End If
Dim oUserFields As SAPbobsCOM.UserFieldsMD
oUserFields = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
Dim isExists As Boolean = False
'LSC 10/20/2013
If Not FieldID = -1 Then 'oUserFields.GetByKey(TableName, FieldID) Then
' oUserFields.Remove()
' If Not isUpdateExisting Then Return True
Return True
'oUserFields.Remove()
End If
With oUserFields
If Not isExists Then
.TableName = TableName
.Name = FieldName
.Description = FieldDescription
.Type = FieldType
End If
.EditSize = UDFLength
.Mandatory = isMandatory
Select Case oUserFields.Type
Case 4
.SubType = FieldSubType
End Select
If FieldType = SAPbobsCOM.BoFieldTypes.db_Alpha Or FieldType = SAPbobsCOM.BoFieldTypes.db_Float Or FieldType = SAPbobsCOM.BoFieldTypes.db_Numeric Or FieldType = SAPbobsCOM.BoFieldTypes.db_Date Then
If Not DefaultValue = "" Then .DefaultValue = DefaultValue
End If
If Not LinkedTable = "" Then .LinkedTable = LinkedTable
If Not IsNothing(dtValidValues) Then
For Loops As Integer = 0 To dtValidValues.Rows.Count - 1
.ValidValues.Value = dtValidValues.Rows(Loops).Item("Value")
.ValidValues.Description = dtValidValues.Rows(Loops).Item("Description")
If Loops <= dtValidValues.Rows.Count - 1 Then .ValidValues.Add()
Next
End If
If isExists Then
If Not .Update = 0 Then
If ShowMessage Then SetMessage(oDICompany.GetLastErrorDescription)
Return False
End If
Else
If Not .Add = 0 Then
If ShowMessage Then SetMessage(oDICompany.GetLastErrorDescription)
Return False
End If
End If
End With
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFields)
oUserFields = Nothing
GC.Collect()
Return True
Catch ex As Exception
SetMessage(ex)
Return False
End Try
End Function -
Version conflict? Error -5002 when adding a sales order in SDK 2004.
I get the -5002 error without any description when I reference the "SAP Business One Objects Bridge API version 6.2 SP3" and try to add an invoice in SBO 2004. The code is basically:
Set vDOC = vCmp.GetBusinessObject(oInvoices)
vDOC.CardCode = "K99999"
vDOC.CardName = "Nils"
vDOC.Lines.ItemCode = "A00001"
VDOC.Add
The routine works well if I reference the SBO 2004 DI API or if I run it on a 6.5 system.
How can I be sure that my routine can work in both versions?
/Nils.
Message was edited by: Nils Jakob HeyerdahlI run Windows XP Proffessional with SP2.
1) I had 6.5 SP1 installed. My POS-app works well. I have a procedure that adds an invoice from the POS-app. The VB-project (VB6 SP5) references "SAP Business One Objects Bridge API version 6.2 SP3" (because I want to support all versions of SBO).
2) I uninstall SBO 6.5 and install SBO 2004 (III).
3) I start the POS-app and receives an error when I try to add a document. The message is "-5002,". No text after the errorcode.
4) I then deletes the reference to "SAP Business One Objects Bridge API version 6.2 SP3" and reference the "SAP Business One DI API Version 2004".
5) I then start the POS-app again and no error occurs.
The code I debuged with is as simple as this:
Set vDOC = vCmp.GetBusinessObject(oInvoices)
Set vOCRD = vCmp.GetBusinessObject(oBusinessPartners)
vDOC.CardCode = "K99999"
vDOC.CardName = "Nils"
vDOC.Add
vDOC.Lines.ItemCode = "A00001"
vDOC.Lines.ProjectCode = " "
vDOC.Lines.ItemDescription = "Varetekst"
vDOC.Lines.Quantity = 1
vDOC.Lines.PriceAfterVAT = 100
vDOC.Lines.DiscountPercent = 0
If (0 <> vDOC.Add()) Then
Call vDOC.SaveXML("SAP_ERR_" & Trim(Str(DocType)) & "_" & Trim(Str(Bong)) + ".xml")
isCancelled = True
End if
Exit Function
Strange?
/Nils. -
Error Message When Adding New User
Hello,
We are on FDM 11.1.2.1.501 and today as I was going to add a new user in the system I got the below error message:
Error: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
After the error the usual user maintenance screen came up and I was able to add the users I needed to without any problems. Anyone have an idea what this error means? Just looking to prevent problems on down the road.
Also, there wasn't anything in the FDM error log nor in the windows event viewer on any of the servers.
Thanks in advance,
JasonOracle was able to provide a solution to this one. Somehow there was a disconnect between HSS and FDM so went into SS and deleted out the affected application. Then went onto the FDM web server and ran the user migration utility to reconnect that application with SS and now it works fine w/out the error message.
-
Can't remove a user defined field with DI API.
Hi,
I'm using the code below to remove a user field. However, the first time I run it, I get the message that:
"Ref count for this object is higher then 0"
The second time I run it, I get the message that:
"No matching records found (ODBC -2028)"
As you can see, I am killing the UserFieldsMD object. In fact, when the function is entered, the object is nothing but later instantiated with oCompany.
The result in both cases is that the field doesn't get removed. What am I missing? Any ideas?
Thanks,
Mike
Public Function RemoveUserField(ByVal FieldName As String, ByVal TableName As String, ByRef ErrMsg As String) As Boolean
Dim Result As Boolean = False
Dim Err As Integer
Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD
Try
If Not FieldExists(TableName, FieldName) Then
Result = True
Else
oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
With oUserFieldsMD
.TableName = TableName
.Name = FieldName
Err = .Remove
If Err Then
oUtilCompany.GetLastError(Err, ErrMsg)
If ErrMsg = "No matching records found (ODBC -2028)" Then
Result = True
Else
ErrMsg = "Was not able to remove field " & FieldName & " from table " & TableName & " programmatically." & vbCrLf & _
"Please remove it manually using the Tools menu."
End If
Else
Result = True
End If
End With
End If
Catch ex As Exception
Throw ex
Finally
KillObject(oUserFieldsMD)
End Try
Return Result
End Function
Public Sub KillObject(ByRef Obj As Object)
If Not Obj Is Nothing Then ObjectRelease(Obj)
End Sub
Private Sub ObjectRelease(ByRef Obj As Object)
'This routine releases objects that were acquired with oCompany.GetBusinessObject().
System.Runtime.InteropServices.Marshal.ReleaseComObject(Obj)
Obj = Nothing
GC.Collect()
End SubHi Mike,
The issue with your code is that you are not calling the GetByKey method of the field object. Until you do this the FieldID property is 0 so when the Remove method is called it will not try and remove the correct UDF (if you run SQL profiler then you'll see that SBO is looking for the UDF based on the table and fieldID values).
Something like the following works for me:
private void DeleteUDF(string sTableID, string sFieldName)
SAPbobsCOM.UserFieldsMD sboField = (SAPbobsCOM.UserFieldsMD)_sboCompany.GetBusinessObject(BoObjectTypes.oUserFields);
try
int iFieldID = GetFieldID(sTableID, sFieldName);
if(sboField.GetByKey(sTableID, iFieldID))
if (sboField.Remove() != 0)_sboApp.SetStatusBarMessage("Error removing UDF: " + _sboCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Short, true);
finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(sboField);
sboField = null;
GC.Collect();
private int GetFieldID(string sTableID, string sAliasID)
int iRetVal = 0;
SAPbobsCOM.Recordset sboRec = (SAPbobsCOM.Recordset)_sboCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
try
sboRec.DoQuery("select FieldID from CUFD where TableID = '" + sTableID + "' and AliasID = '" + sAliasID + "'");
if (!sboRec.EoF) iRetVal = Convert.ToInt32(sboRec.Fields.Item("FieldID").Value.ToString());
finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(sboRec);
sboRec = null;
GC.Collect();
return iRetVal;
Note that the parameter sAliasID is the field name without the U_ prefix.
Kind Regards,
Owen -
Add Link button in UDF(User Defined Field)
How Can be add link Button when create new user Defined Field ?
Hi,
You can bring the link button in user designed forms using SDK, but you cannot create the Link button in SAP standard forms. It's hard to bring the link button in SAP standard forms.
Raja.S -
User Defined field and User defined values.
Curently testing this in the demo database before rolling it out to a customer.
I added a user defined field to my item master data base called Lengthcm of type Amount.
I have created a query:
SELECT u_lengthcm = CASE
WHEN $[oitm.blen1unit] = 5 THEN $[oitm.blength1] * 2.54
WHEN $[oitm.blen1unit] = 6 THEN $[oitm.blength1] * 2.54 * 12
ELSE 0 END
Length unit 5 is inches and length unit 6 is feet.
In Item Maintenance then I create a user defined value for the lengthcm field linked to the query and set to auto-update when the blength1 field changes.
This works perfectly for 1 inch through 9 inches (1" through 9") and fills in the centimeter value. When I put in a value in feet (1', 2'), it does nothing and if I put in any value of 10" or greater gives an error message:
[Microsoft][SQL Server Native Client 10.0][SQL Server] Arithmetic overflow error
converting nvarchar to data type numeric. 'Received Alerts' (OAIB).
Checking database structure back end, blen1unit is of type small int, blength1 is numeric of size 19, 6 and so is my lengthcm field.
Edited by: Danielle Ostach on Mar 18, 2011 8:18 PM
Edited by: Danielle Ostach on Mar 18, 2011 8:19 PM
Edited by: Danielle Ostach on Mar 18, 2011 8:20 PM
Edited by: Danielle Ostach on Mar 18, 2011 8:21 PM
Edited by: Danielle Ostach on Mar 18, 2011 8:21 PMHi Danielle ,
Try this...
SELECT u_lengthcm = CASE
WHEN $[oitm.blen1unit] = 5 THEN (cast(($[oitm.blen1unit]) as decimal(19,6))) * 2.54
WHEN $[oitm.blen1unit] = 6 THEN (cast(($[oitm.blen1unit]) as decimal(19,6))) * 2.54 * 12
ELSE 0 END
Regards,
Sachin
Maybe you are looking for
-
I would like to purchase an app but it requires an operating system of OS X 10.7.3 or later and I only have 10.6.8 What do I need to do? Can I get that on my MacBook?
-
Strange folders appearing in LiveType Project directory
Running FCP 5.04 under 10.4.7. LiveType 2.0.2 Just upgraded from OS X 10.3.9, FCP 4.5 and LiveType 1.2. We did not see this issue prior to the update. LiveType is placing 0 Kb folders in my LiveType project directory every time I save (as) a LiveType
-
Building an application that does not use any local program files or libraries
I need to build an application that will not use any local libraries or LabView program files(even if LabView is installed on the PC). I also am curious if anyone knows if there is a way to debug such an application(in it's compiled state). Any help
-
Error iTunes library file cannot be saved. A folder was specified instead of a file.
I keep getting this error "The iTunes library file cannot be saved. A folder was specified instead of a file." I keep my library on mu drive and my music folder on a networked drive. There appears to be nothing I can do to correct this. Any sugges
-
In the Edit>Preferences>External Editors tab, the primary external editor (photoshop) says Edit in Photoshop (not found). I do have Photoshop CS installed but wonder why it says (not found). To work around, I have defined a second editor to be Photos