Skip to Content
avatar image
Former Member

Error in creating userkey ---- UserKeysMD

Hi,

I am trying to add a primary key through UserKeysMD in a user defined table.But It is showing the invalid field name error,

Pls help me

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Dec 30, 2005 at 09:43 AM

    Try the following... that work for me:

    UserKeysMD keyMd = (UserKeysMD)SboCompany.GetBusinessObject(BoObjectTypes.oUserKeys);
    keyMd.TableName = "TableName";
    keyMd.KeyName = "KeyName";
    keyMd.Elements.ColumnAlias = "Field"; 
    keyMd.Unique = BoYesNoEnum.tYES;
    keyMd.Add();
    

    Message was edited by: Rasmus Jensen

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 30, 2005 at 09:37 AM

    Hi yash sharma

    Must amke sure the table and the field exists in that database, then do not put in your code the "@" symbol or the "U_" symbol. Also the field should not have dupliacte data.Once you have added the key look in OUKD, this is where sap stores the MDKeys.

    Here is sample code if you do it in vb

    Dim UserKey As SAPbobsCOM.UserKeysMD

    UserKey = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserKeys)

    Try

    UserKey.TableName = "SM_OPED"

    UserKey.KeyName = "test"

    UserKey.Elements.ColumnAlias = "Proc"

    UserKey.Unique = SAPbobsCOM.BoYesNoEnum.tYES

    lRetCode = UserKey.Add

    If lRetCode <> 0 Then

    oCompany.GetLastError(lRetCode, sErrMsg)

    MsgBox(sErrMsg)

    End If

    Catch ex As Exception

    MsgBox(ex.Message)

    End Try

    The above works and adds one key.

    Hope this helps 😊

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      I have a UDT whith a UDF created throw the SAP BO Application, and need to enforce a unique constraint.

      I used the sample code provided by Louis but

      the UserKet.Add returns error code

      -5002 : Invalid field name

      UserKey.TableName = "MGCF" 'The UDT Name

      UserKey.KeyName = "KeyCCode" 'The Key Name

      UserKey.Elements.ColumnAlias = "CCode" 'The Column Name

      UserKey.Unique = SAPbobsCOM.BoYesNoEnum.tYES

      What Have i done wroung?

      Thanks Pedro Gomes.

  • avatar image
    Former Member
    Oct 03, 2006 at 03:08 PM

    Make sure the field's names you're indexing (then Elements.ColumnAlias) are less o equal than 8 characters (it gives me a lot of headaches...)

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      I've deleted my UDT an created it again this time in code

      after i've added the UDF also in code

      the same error ocurres when i try to create the unique constraint

      code i used for creating the key.

      oUserKeysMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserKeys)

      oUserKeysMD.TableName = "MGCF"

      oUserKeysMD.KeyName = "Key_CCode"

      oUserKeysMD.Elements.ColumnAlias = "CCode"

      oUserKeysMD.Unique = SAPbobsCOM.BoYesNoEnum.tYES

      If oUserKeysMD.Add <> 0 Then

      BO_Application.MessageBox(oCompany.GetLastErrorDescription())

      End If

      if anyone cam spot the bug please let me know

      Thanks Pedro Gomes