Skip to Content
avatar image
Former Member

user defined fields via DI-API

I want to read user defined fields using the DI-API.

The following code works but lists only UDFs defined for articles:

SAPbobsCOM.Items item = 
(SAPbobsCOM.Items) GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);	
int count = item.UserFields.Fields.Count;
MessageBox.Show("count == "+anzahl.ToString(), "OK");
for(int i=0; i<count; i++){
  MessageBox.Show("index == "+i.ToString(), "OK");
  MessageBox.Show("name == "+item.UserFields.Fields.Item(i).Name, "OK");

If I try to list all UDFs defined in the system using the oUserFields object I get an exception when I assign the business object:

  SAPbobsCOM.UserFields ufd = (SAPbobsCOM.UserFields) 
  GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); // exception

  int count = ufd.Fields.Count;

catch(System.Exception ex){
  MessageBox.Show("ex.ToString(), "OK");

The exception says something like

InvalidCastException: COM object of type 'System.__ComObject' can not casted into

interface type SAPbobsCOM.UserFields

Thank you for help,

Frank Romeni

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 04, 2008 at 06:09 PM


    The BoObjectTypes.oItems represents the Items object (Main MenuStock ManagementItem Master Data).

    the BoObjectTypes.oUserFields is connected to the UserFieldsMD object.

    Can you explain what you are trying to do?


    Vítor Vieira

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member David Nussböck

      Hallo David,

      zunächst mal 10 Punkte für Dich!

      Zu Deiner Frage ("ich versteh ehrlich gesagt nicht warum ..."): Ganz einfach, weil ich gerade neu mit dem DI anfange und der Begriff 'Index' mich automatisch nur an int hat denken lassen ... das zum Thema selbsterklärende Namen ...


      Gruß Frank

  • avatar image
    Former Member
    Sep 05, 2008 at 07:09 AM

    Dear Frank Romeni,

    UserFieldsMD is a business object that enables you to mange user defined fields.

    The main function like add, update ... a UDF.

    It is not a user fields collection object and you could not use it for your UDF retrieve requirement.

    The basic way to access a UDF is first get the object, such as Item object,

    then get the UDF belong the object by item.UserFields.

    Best Regards

    Jane Jing

    SAP Business One Forums team

    Edited by: Jane Jing on Sep 5, 2008 9:10 AM

    Add comment
    10|10000 characters needed characters exceeded