Skip to Content

Read data from a Form reliably

I am using SAP Business One 9.2 SDK UI API (C#) and to get data from a System Form when the user submits it, I catch the FormDataEvent (BusinessObjectInfo.BeforeAction && BusinessObjectInfo.Type == ...) and grab the form's Item and read the value. The problem with this is I need to switch panes in order to read the data from a field.

Form itemForm = SBOApp.Forms.Item(formUid);
itemForm.PaneLevel = 2;
EditText salUnitMsrItem = (EditText)itemForm.Items.Item("55").Specific;
string theValue = salUnitMsrItem.Value;

If the user in SAP moves the field to another Tab my data from the PaneLevel will be out of snyc and the addon will crash with an Invalid Item exception.

Can I grab an item's Value without switching the Panes (maybe with DataSources somehow? Can I identify the Item's datasource with an Item's ID?) Also, the User defined fields are on a different form, which I can grab with

Form oFormU = SBOApp.Forms.Item(oForm.UDFFormUID);

But the user can move a User Defined field into the system form's pane...

The UI Changes I mentioned are done with the UI Configuration Template:

http://www.achieveits.com/pdf/business-one/how_to_work_with_configurable_ui_templates.pdf

Edit.: I forgot to mention, I need this functionality to validate data the user would like to insert. For example check if there is field filled in while another is not and display a MessageBox asking if he would like to continue even though an information is missing. Also I need to check the database for a few times too.

Add comment
10|10000 characters needed characters exceeded

  • Hi Szabolcs,

    You don't need to hardcode the panelevel, get it from the item properties it self.

    I agree that this is troublesome and should have a better way to do.

    Form itemForm = SBOApp.Forms.Item(formUid);
    SAPbouiCOM.Item item = itemForm.Items.Item("55"); itemForm.PaneLevel =item.FromPane; EditText salUnitMsrItem =(EditText)item.Specific();
    string theValue = salUnitMsrItem.Value;
  • Oh, I totally missed that. Thanks you really!

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 17, 2016 at 10:47 AM

    Hi Szabolcs,

    For read data from a System form you can use DBDataSource, and you won't find problem with panel level with this resource. DBDataSource is a representation of a Table in the form. For example, suppose that you want get some data from Sales Order Form, you can do something like this:

    SAPbouiCOM.DBDataSource db = oForm.DataSources.DBDataSources.Item("ORDR");
         //sample db.GetValue("DocEntry", 0);
         string value = db.GetValue("your user field/ or system field", 0);
    

    The first parameter is the name or index of the field that you want, and the second parameter is the position of the register. In the sales order form for example, ORDR have only one register and the value that you provide in the method is 0, but if you want get some data from RDR1, you can provide what exactly the index of the line that you want.

    Hope it helps.

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded

    • Unfortnally yes, in this case you need access Item, and change panellevel to achieve access to itens from another panels.

      I just know this way to write data in the system form. :(

      Kind Regards,

      Diego Lother

  • Nov 17, 2016 at 01:39 PM

    Hi Szabolcs,

    You should in almost every situation use the datasources bound to the items to read the data.

    Datasources can be DBDataSource, DataTable or UserDataSource. You can read data from these regardless of pane-level, item status, etc...

    You can check the SDK Help Center file for usage examples.

    Pedro Magueija

    LinkedIn | Twitter | Blog

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Szabolcs,

      Buttons have no datasource because they don't have any "data". They have properties with values, but not "data" to say persist in a database.

      When we refer to "data" it mostly the "business data". Not the properties.

      To access the properties you need the item itself (button, edit text, etc...).

      Note also that in my post I said: "read data". Writing "business data" to system forms is not allowed using the "datasources".

      Pedro Magueija

      LinkedIn | Twitter | Blog