Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

UDF in SPP1

Hi,

In the DI Reference, I see that there's a UserFields property for the SpecialPricesDataArea, i.e. the SPP1 table. Yet, there's no way to add user fields to this object via the user interface.

Is it possible that I will add a "U_test" field to the SPP1 table manually, via SQL, and use it with the UserFields property?

Former Member
replied

Hi Avi,

The UserFieldsMD object in the DI API is used to add UDFs to tables. Here's an example from the SDK Help Center:

Private Sub AddUserField()

'//****************************************************************************
'// The UserFieldsMD represents a meta-data object that allows you
'// to addremove fields from tables or change the fields' characteristics
'//****************************************************************************

    Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD

'//****************************************************************************
'// In any meta-data operation there should be no other object "alive"
'// but the meta-data object, otherwise the operation will fail.
'// This restriction is intended to prevent a collisions.
'//****************************************************************************

    '// The meta-data object needs to be initialized with a
    '// regular UserFields object
    Set oUserFieldsMD = oCompany.GetBusinessObject(oUserFields)

    '//**************************************************
    '// When adding user tables or fields to the SAP Business One database
    '// use a prefix identifying your partner name space
    '// this will prevent collisions between the various partners add-ons
    '//
    '// SAP's name space prefix is "BE_"
    '//**************************************************

    '// Set the Fields' mandatory properties

    oUserFieldsMD.TableName = "OCRD" '// BP table
    oUserFieldsMD.Name = "BE_UserField1"
    oUserFieldsMD.Description = "A user field"
    oUserFieldsMD.Type = db_Alpha '// am alphanumeric type
    oUserFieldsMD.EditSize = 20

    '// Add the field to the table
    oUserFieldsMD.Add

End Sub

One thing to be particularly aware of is that you can have only one instance of this object alive at any time. Therefore, it is a good idea to use the following code (after the Add method has been called) to 'kill' your current UDF object before attempting to add a new one:

System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
oUserFieldsMD = Nothing
GC.Collect()

Kind Regards,

Owen

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question