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.
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!
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
I see, thanks. I will use that to grab the values from now on.
Also, I commented on @pedro.magueija 's comment.
Is it possible to set the value of a User Defined Field through here? It worked for the system fields with
oForm.DataSources.DBDataSources.Item(DatabaseTable).SetValue(FieldName, 0, newValue);
But with an UDF it throws
{"Item - The item is not a user-defined item [66000-8]"} System.Runtime.InteropServices.COMException
Hi Szabolcs,
DBDataSources and others DataSources and objects related by Pedro, are objects to read and write data to form, not to change properties of the controls on the form. If you want change the taborder for example, you need to use the Items object.
The method SetValue of DBDataSource just work for user defined forms with user tables, we are not able to write values in DBDataSource related to a System Form or System Table, even than the field of the table is a user defined field.
Hope it helps.
Kind Regards,
Diego Lother
I just wanted to make a keyboard shortcut, which copies some field from the Items From, creates a new Items Form and sets those fields. But I guess I cannot do that without using the PaneLevel and direct Item access. :(
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
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
I see, but what to do about Buttons? Buttons have no DataSources and the users can move them too and If They want to.
Also, what If I want to change the way an EditText looks or replace it, or change the TabOrder? I still would need to get an EditText object, so I need to switch to the Pane and if the user moves it, it will no longer work.
(I just don't understand why there isn't a general, always working solution for getting a form's Item, reading the value from the DataSource's solves many on my problems now, but I would like to change the TabOrder too, so I need to load the Items directly).
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