cancel
Showing results for 
Search instead for 
Did you mean: 

DI - Setting UDF values

Former Member
0 Kudos

(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 vb.net but will take anything!)

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

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

While en.MoveNext

Console.WriteLine(en.Current.name)

Console.WriteLine(en.Current.description)

Console.WriteLine(en.Current.value)

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.

myItem.UserFields.Fields.Item(4).Value

myItem.UserFields.Fields.Item("U_toBasePart").Value

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

Any help would be appreciated.

Thanks!

TB

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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,

Adele

Former Member
0 Kudos

What I am seeing is that I must do an item add in two steps using the following technique.

1) I must add the part

2) Then, I must update the UDF values.

If I try it in one step, I don't get an error but the values do not go into the table.

I wonder if the SBO UI stores values in more than one step as well? Possible bug here...

Here is the method I am using to add items through the DI -

Basically I do the following - (Enum values in string form for clarity)


Dim myItem As SAPbobsCOM.Items myItem = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)

Dim UpdateMode As Boolean
UpdateMode = myItem.GetByKey(TextBox1.Text.Trim)
 With myItem
            .ItemCode = String
            .ItemName = String
            .BarCode = String
            .ItemType = SAPbobsCOM.ItemTypeEnum.itItems
            .ItemsGroupCode = String
            .InventoryItem = SAPbobsCOM.BoYesNoEnum.tYES
            .SalesItem = SAPbobsCOM.BoYesNoEnum.tYES
            .UserFields.Fields.Item("U_Field1").Value = TextBox17.Text
            .UserFields.Fields.Item("U_Field2").Value = TextBox36.Text
            .UserFields.Fields.Item("U_Field3").Value = TextBox35.Text
            .UserFields.Fields.Item("U_Field4").Value = TextBox34.Text

 End With

 If UpdateMode Then
     lRetCode = myItem.Update
 Else
     lRetCode = myItem.Add
 End If
End Sub

Also, anyone who has code for working with UDF enumerations, please post! Thanks again.

Former Member
0 Kudos

Hi Ty,

I don't exactly understand what you mean with your question, but it sounds like your values aren't saved if you set properties and UDFs values at the same time when adding? I executed the following code to test your problem and it saved the item with the values of the UDFs.

        Dim oItem As SAPbobsCOM.Items
        oItem = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
        oItem.ItemCode = "XXXXX"
        oItem.ItemName = "Item XXXXXXXX"
        oItem.UserFields.Fields.Item("U_Billable").Value = "Y"
        If oItem.Add <> 0 Then
            MessageBox.Show(oCompany.GetLastErrorDescription)
        End If

Hope it helps,

Adele

Former Member
0 Kudos

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.

Cheers!

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)
        TextBox8.Clear()
        If UpdateMode Then
            TextBox8.Text = "Part " + TextBox1.Text + " already in database." + vbCrLf
        Else
            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
            myItem.WhsInfo.Add()
            .PlanningSystem = SAPbobsCOM.BoPlanningSystem.bop_MRP
            .PriceList.SetCurrentLine(CInt(TextBox19.Text))
            .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

        Try

            If UpdateMode Then
                lRetCode = myItem.Update
            Else
                lRetCode = myItem.Add
            End If

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
        If lRetCode <> 0 Then
            oCompany.GetLastError(lErrCode, sErrMsg)
            TextBox8.Text = TextBox8.Text + ("ERROR!" + lErrCode.ToString & " " & sErrMsg)  ' Display error message
        Else
            TextBox8.Text = TextBox8.Text + "Success!"
        End If

    End Sub