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

DI - Setting UDF values

(PL4, SP01)

A couple of questions -

1) Is there example code for working with UDFs through the DI?

2) Does anyone have code for working with UDF enumerations? (I prefer but will take anything!)

(example of what I want to do...)

Dim en As IEnumerator = myItem.UserFields.Fields.GetEnumerator

While en.MoveNext




End While

3) I am having all sorts of trouble working with UDF values on PL4 SP01. I have tried working with both "named" values and "index" numbers.



I want to try working with the enumerations to help debug my problems.

Any help would be appreciated.



Add comment
10|10000 characters needed characters exceeded

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Aug 03, 2006 at 05:26 AM

    Hi Ty,

    What you are doing seems to be right. Are you getting any errors? Why does it not work for you. Here's an example of how to save values to UDT:

    Dim oTable As SAPbobsCOM.UserTable
    oTable = oCompany.UserTables.Item(T_REGISTER)
    oTable .Code = iCode
    oTable .Name = sAddOnName
    oTable .UserFields.Fields.Item("U_MyField").Value = "Test"

    Hope it helps,


    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Thanks very much Adele.

      Your code is almost exactly what I am doing.

      Here is the difference -

      I am setting 4 UDF values.

      If I ADD a part, sometimes the values get set and sometimes they do not. If I follow up with an immediate update, all values are set OK.

      I have checked the fields in OITM and the values that aren't set contain <NULL>

      It is making me a little crazy. 😊

      If you could possibly find the time, I would appreciate it if you could do a little further testing with your app.

      Perhaps 4 UDFs. My UDFS are AlphaNumeric 10. They DO have lists of valid values setup for each field as well.

      If you could do that, it would help me a lot. I hate to be a pessimist, but I really hope your code fails 😊 then I would not feel so crazy!

      I am using PL4, SP01. My sbobobscom2005.dll version is 6.80.317.0

      I am using VS 2003 for this one.


      The actual code for the entire sub follows

          Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
              Dim myItem As SAPbobsCOM.Items
              myItem = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
              Dim UpdateMode As Boolean
              UpdateMode = myItem.GetByKey(TextBox1.Text.Trim)
              If UpdateMode Then
                  TextBox8.Text = "Part " + TextBox1.Text + " already in database." + vbCrLf
                  TextBox8.Text = "Part " + TextBox1.Text + " not in database." + vbCrLf
              End If
              With myItem
                  .ItemCode = TextBox1.Text.Trim
                  .ItemName = TextBox2.Text.Trim
                  .BarCode = TextBox3.Text.Trim
                  .ItemType = SAPbobsCOM.ItemTypeEnum.itItems
                  .ItemsGroupCode = ComboBox1.SelectedValue
                  .InventoryItem = SAPbobsCOM.BoYesNoEnum.tYES
                  .SalesItem = SAPbobsCOM.BoYesNoEnum.tYES
                  .PurchaseItem = SAPbobsCOM.BoYesNoEnum.tNO
                  .ProcurementMethod = SAPbobsCOM.BoProcurementMethod.bom_Make
                  .Manufacturer = TextBox15.Text
                  .AssetItem = SAPbobsCOM.BoYesNoEnum.tNO
                  .TaxType = SAPbobsCOM.BoTaxTypes.tt_Yes
                  .ManageBatchNumbers = SAPbobsCOM.BoYesNoEnum.tNO
                  .ManageSerialNumbers = SAPbobsCOM.BoYesNoEnum.tNO
                  .PurchaseUnit = TextBox10.Text
                  .PurchaseItemsPerUnit = TextBox9.Text
                  .PurchasePackagingUnit = TextBox32.Text
                  .PurchaseQtyPerPackUnit = TextBox31.Text
                  .SalesUnit = TextBox30.Text
                  .SalesItemsPerUnit = TextBox29.Text
                  .SalesPackagingUnit = TextBox28.Text
                  .SalesQtyPerPackUnit = TextBox27.Text
                  .GLMethod = SAPbobsCOM.BoGLMethods.glm_ItemClass
                  .CostAccountingMethod = SAPbobsCOM.BoInventorySystem.bis_FIFO
                  .DefaultWarehouse = TextBox24.Text
                  .ManageStockByWarehouse = SAPbobsCOM.BoYesNoEnum.tYES
                  .InventoryUOM = TextBox22.Text
                  .WhsInfo.WarehouseCode = TextBox21.Text
                  .PlanningSystem = SAPbobsCOM.BoPlanningSystem.bop_MRP
                  .PriceList.Price = CDbl(TextBox18.Text)
                  .UserFields.Fields.Item("U_toPrimaryDept").Value = TextBox17.Text
                  .UserFields.Fields.Item("U_toItemSecondDept").Value = TextBox36.Text
                  .UserFields.Fields.Item("U_toItemType").Value = TextBox35.Text
                  .UserFields.Fields.Item("U_toBasePart").Value = TextBox34.Text
              End With
                  If UpdateMode Then
                      lRetCode = myItem.Update
                      lRetCode = myItem.Add
                  End If
              Catch ex As Exception
              End Try
              If lRetCode <> 0 Then
                  oCompany.GetLastError(lErrCode, sErrMsg)
                  TextBox8.Text = TextBox8.Text + ("ERROR!" + lErrCode.ToString & " " & sErrMsg)  ' Display error message
                  TextBox8.Text = TextBox8.Text + "Success!"
              End If
          End Sub