Skip to Content
author's profile photo Former Member
Former Member

-1120 Ref count for this object is higher then 0.

Hi friends,

I need to two user defined fileds to ORDR,OPOR and ORND,When i try to add i got error like "-1120 Ref count for this object is higher then 0.".How i can solve this.Please Help me

sample code

-


SAPbobsCOM.UserFieldsMD oUserFieldsMD = null;

oUserFieldsMD = ((SAPbobsCOM.UserFieldsMD)(oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)));

oUserFieldsMD.TableName = "ORDR";

oUserFieldsMD.Name = "Branch";

oUserFieldsMD.Description = "Branch";

oUserFieldsMD.Type = 0;//alpha

oUserFieldsMD.EditSize = 100;

iErrorCode = oUserFieldsMD.Add();

//Adding the Field instance

oUserFieldsMD.TableName = "ORDR";

oUserFieldsMD.Name = "Instance";

oUserFieldsMD.Description = "Local/Interstate";

oUserFieldsMD.Type = 0;

oUserFieldsMD.EditSize = 100;

iErrorCode = oUserFieldsMD.Add();

// Check for errors

if (iErrorCode != 0)

{

sErrorMsg = oCompany.GetLastErrorDescription();

SBO_Application.MessageBox(sErrorMsg, 1, "Ok", "", "");

}

else

{

SBO_Application.MessageBox("User Field added Successfully", 1, "Ok", "", "");

}

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 07:15 AM

    Hi Sana,

    You must to reinitialize your oUserFieldsMD variable like this :

    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)

    oUserFieldsMD = Nothing

    oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

    so your code become :

    SAPbobsCOM.UserFieldsMD oUserFieldsMD = null;

    oUserFieldsMD = ((SAPbobsCOM.UserFieldsMD)(oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)));

    oUserFieldsMD.TableName = "ORDR";

    oUserFieldsMD.Name = "Branch";

    oUserFieldsMD.Description = "Branch";

    oUserFieldsMD.Type = 0;//alpha

    oUserFieldsMD.EditSize = 100;

    iErrorCode = oUserFieldsMD.Add();

    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)

    oUserFieldsMD = Nothing

    oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

    //Adding the Field instance

    oUserFieldsMD.TableName = "ORDR";

    oUserFieldsMD.Name = "Instance";

    oUserFieldsMD.Description = "Local/Interstate";

    oUserFieldsMD.Type = 0;

    oUserFieldsMD.EditSize = 100;

    iErrorCode = oUserFieldsMD.Add();

    Hope i help you

    Michael

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Sana,

      I'm try your code on my database and it's work correctly.

      I'm on SAPB1 2005A SP01 PL39.

      Are you an another declaration of MD in your code ?

      Example : you can't have this declaration in the same function

      SAPbobsCOM.UserFieldsMD oUserFieldsMD AND dim oUserTablesMD As SAPbobsCOM.UserTablesMD

      Michael

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 07:51 AM

    Sana,

    this error usually comes when you are adding/doing any metadata operations when other metadata objects are still live with their reference.

    your code looks fine. just add a couple of lines as shown below.

    Try
                SBO_Application.StatusBar.SetText("Please wait till the fields are created.", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
    
                Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD
                oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
                oUserFieldsMD.TableName = Tablename
                oUserFieldsMD.Name = FieldName
                oUserFieldsMD.Description = FieldDes
                oUserFieldsMD.Type = FieldType
                oUserFieldsMD.SubType = FieldSubType
                If FieldType = 2 Or FieldType = 0 Then
                    oUserFieldsMD.EditSize = FieldSize
                End If
                AddT = oUserFieldsMD.Add
    
                If AddT <> 0 Then
                    oCompany.GetLastError(lErrCode, sErrMsg)
                    MsgBox(sErrMsg)
                Else
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
                    oUserFieldsMD = Nothing
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    

    please change the variable name accordingly.

    also if before adding this fields, you are adding table or creating recordset, you will have to set their object to 'nothing' as shown above.

    still face problem, write back.

    Binita

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Sana,

      your code looks fine with a couple of change. but, why on menu event? besides, you will have to check whether the field is already added in cufd table or not. if not, then only you should add it. I still maintain, what operations you are doing before this menu click event fires, is important. such as using a recordset, creating any other field or table etc. and in all cases, you will have to set the respective metadata object to nothing.

      in your code, i think the order in which following lines are written is problematic,

       System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
                              oUserFieldsMD = null
                              oUserFieldsMD = (SAPbobsCOM.UserFieldsMD)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
      
      

      try using the code i posted before. it works. let me know.

      Binita

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 11:46 AM

    This error occurs when in one sub you will create user tables and user fields as well. Split this to step into 2 subs and it will works.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 09:40 AM

    Thanks binitha i got it.I moved that code to constructor.Then it worked.

    Edited by: Sana Samuel on Jun 19, 2008 11:48 AM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.