cancel
Showing results for 
Search instead for 
Did you mean: 

Error while adding a User Defined Field

Former Member
0 Kudos
468

Hi Experts,

I am trying to add a UDF to the OCPR table with some valid values.

If the field already exists, we are getting a message 'ODBC -2035' Field already exists.

After upgrading to SAP 90 version, if the UDF is already there, I am getting an error with Code (-5002) with description ('No Records').

This is the code i am running

SAPbobsCOM.UserFieldsMD oUsrField = null;

            int lErrCode; string sErrCode = "";

            try

            {

                oUsrField = (SAPbobsCOM.UserFieldsMD)pSAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);

                oUsrField.TableName = "OCPR";

                oUsrField.Name = "CntType";

                oUsrField.Type = SAPbobsCOM.BoFieldTypes.db_Alpha;

                oUsrField.Description = "Contact Type";

                oUsrField.Size = 253;

                oUsrField.EditSize = 253;

                oUsrField.ValidValues.Value = "None";

                oUsrField.ValidValues.Description = "None";

                oUsrField.ValidValues.Add();

                oUsrField.ValidValues.Value = "B1";

                oUsrField.ValidValues.Description = "Bill To 1";

                oUsrField.ValidValues.Add();

                oUsrField.ValidValues.Value = "S1";

                oUsrField.ValidValues.Description = "Ship To 1";

                oUsrField.ValidValues.Add();

                oUsrField.ValidValues.Value = "B2";

                oUsrField.ValidValues.Description = "Bill To 2";

                oUsrField.ValidValues.Add();

                oUsrField.ValidValues.Value = "S2";

                oUsrField.ValidValues.Description = "Ship To 2";

                oUsrField.ValidValues.Add();

                lErrCode = oUsrField.Add();

                if (lErrCode == 0)

                    return 0;

                else

                {

                    pSAPCompany.GetLastError(out lErrCode, out sErrCode);

                    throw new Exception("Error creating APP Contact Types field : " + sErrCode);

                }

            }

            catch (Exception ex)

            {

                throw ex;

            }

            finally

            {

                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUsrField);

                oUsrField = null;

                GC.Collect();

            }

Please help me to find out the reason of this error.

Thanks in advance.

Jisha

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member201110
Active Contributor
0 Kudos

Hi Jisha,

You need to call the Add method for the ValidValues object first and then use SetCurrentLine before setting your valid value properties:

oUsrField.ValidValues.Add()

oUsrField.ValidValues.SetCurrentLine(0)

oUsrField.ValidValues.Value = "None";

oUsrField.ValidValues.Description = "None";

oUsrField.ValidValues.Add()

oUsrField.ValidValues.SetCurrentLine(1)

oUsrField.ValidValues.Value = "B1";

oUsrField.ValidValues.Description = "Bill To 1";

etc

Kind Regards,

Owen