cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from a datafield on a form

Former Member
0 Kudos

Hi everybody,

I'm completely new in sap business one and I'm having a problem concerning the sdk.

I added a button to the businesspartner form next to the phone1 field. Then I tried to read the phonenumber-value from item number 43 (phone1) on the businesspartner-form (form number 134), when you click on the button. I want to save this value in a temp variable in my visual-basic code.

I tried a lot and searched the sdk-examples but didn't find any working solution.

Is it possible to read the field-value from the form by using the ui-sdk or do I have to use the di-sdk?

If possible, could anyone please post a code-example in vb6?

Thanks very much!

Regards,

Tim Jaschik

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, Tim!

Just have a look on the examples, that you can find in the SAP-installation directory - "..\SAP Manage\SAP Business One SDK\Samples\COM UI\VB6\11.SystemFormManipulation"

As for Edit item - if u wanna get the value, you can use "String" or "Value" prorerty of an Edit object...

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Aleksey,

I tried your solution, but the error still occured. After that I realized, that I didn't set the variable of the textfield correctly. I added "Set" to the code an until now it works fine. The code have to look like this:

Set edBPhone = oBPForm.Items.Item("43").Specific

Thank you for the time you spend solving my problem.

Regards,

Tim Jaschik

Former Member
0 Kudos

Hi again,

I tried your solution, but I receive an error:

Run-time error '438'

Object doesn't support this property or methode

This error appears when clicking on the button. In the debugging-modus, the error occurs in the "ReadPhoneFieldValue" function in the line:

edBPhone = oPBForm.Items.Item("43").Specific

To make it easier to understand, I've posted the complete code below.

In the function "AddItemsToBPForm" I add a textfield an a button to the BPForm.

When clicking on the button, in the eventhandler, I call the function "ReadPhoneFieldValue" to get the value out of the phonenumberfield and write it into the textfield.

At the moment, I want to get a messagebox with the phonenumber to test the application.

Hopefully any of you have the time to help me.

Thanks.

Tim Jaschik

'// SAP MANAGE UI API 2005 SDK Sample

'//****************************************************************************

'//

'// File: OrderFormManipulation.cls

'//

'// Copyright (c) SAP MANAGE

'//

'// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF

'// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO

'// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A

'// PARTICULAR PURPOSE.

'//

'//****************************************************************************

'//**************************************************************************************************

'// BEFORE STARTING:

'// 1. Add reference to the "SAP Business One UI API"

'// 2. Insert the development connection string to the "Command Line Argument"

'//----


'// 1.

'// a. Project->References

'// b. check the "SAP Business One UI API" check box

'//

'// 2.

'// a. Project->Properties

'// b. choose 'Make' tab folder

'// c. place the following connection string in the 'Command Line Arguments' field

'// 0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056

'//

'//**************************************************************************************************

Option Explicit

'//*****************************************************************

'// At the begining of every UI API project we should first

'// establish connection with a running SBO application.

'*******************************************************************

Private WithEvents SBO_Application As SAPbouiCOM.Application

Private oBPForm As SAPbouiCOM.Form

Private oNewItem As SAPbouiCOM.Item

Private oItem As SAPbouiCOM.Item

Private oFolderItem As SAPbouiCOM.Folder

Private oOptionBtn As SAPbouiCOM.OptionBtn

Private oCheckBox As SAPbouiCOM.CheckBox

Private edBPhone As SAPbouiCOM.EditText

Private oEditText2 As SAPbouiCOM.EditText

Private oButton As SAPbouiCOM.Button

Private i As Integer '// to be used as a counter

Private Sub SetApplication()

'*******************************************************************

'// Use an SboGuiApi object to establish the connection

'// with the application and return an initialized appliction object

'*******************************************************************

Dim SboGuiApi As SAPbouiCOM.SboGuiApi

Dim sConnectionString As String

Set SboGuiApi = New SAPbouiCOM.SboGuiApi

'// by following the steps specified above, the following

'// statment should be suficient for either development or run mode

sConnectionString = Command

'// connect to a running SBO Application

SboGuiApi.Connect sConnectionString

'// get an initialized application object

Set SBO_Application = SboGuiApi.GetApplication()

End Sub

Private Sub AddItemsToBPForm()

'// add a user data source

'// bear in mind that every item must be connected to a data source

oBPForm.DataSources.UserDataSources.Add "Edit1", dt_SHORT_TEXT, 254

'Add EditText

Set oItem = oBPForm.Items.Item("54")

Set oNewItem = oBPForm.Items.Add("Edit1", it_EDIT)

oNewItem.Left = 100

oNewItem.Width = 100

oNewItem.Top = 100

oNewItem.Height = 100

oNewItem.FromPane = 0

oNewItem.ToPane = 1

Set edBPhone = oNewItem.Specific

'Add Button

Set oItem = oBPForm.Items.Item("1")

Set oNewItem = oBPForm.Items.Add("Button1", it_BUTTON)

oNewItem.Left = 250

oNewItem.Width = 100

oNewItem.Top = 250

oNewItem.Height = 50

oNewItem.FromPane = 0

oNewItem.ToPane = 1

Set oButton = oNewItem.Specific

oButton.Caption = "Phone"

End Sub

Private Sub Class_Initialize()

'//*************************************************************

'// set SBO_Application with an initialized application object

'//*************************************************************

SetApplication

End Sub

Private Sub ReadPhoneFieldValue()

Dim Text As String

edBPhone = oBPForm.Items.Item("43").Specific

Text = edBPhone.Value

SBO_Application.MessageBox (Text)

End Sub

Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, pVal As SAPbouiCOM.IItemEvent, BubbleEvent As Boolean)

If ((pVal.FormType = 134 And pVal.EventType <> et_FORM_UNLOAD) And (pVal.Before_Action)) Then

'// get the event sending form

Set oBPForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount)

If ((pVal.EventType = et_FORM_LOAD) And (pVal.Before_Action = True)) Then

AddItemsToBPForm

End If

If pVal.EventType = et_ITEM_PRESSED And pVal.ItemUID = "Button1" Then

ReadPhoneFieldValue

End If

End If

End Sub

Private Sub SBO_Application_AppEvent(ByVal EventType As SAPbouiCOM.BoAppEventTypes)

Select Case EventType

Case aet_ShutDown:

'// Take care of terminating your AddOn application

SBO_Application.MessageBox ("A Shut Down Event has been caught" & _

vbNewLine & "Terminating 'Order Form Manipulation' Add On...")

End

End Select

End Sub

Former Member
0 Kudos

Hi, Tim,

I think the reason is in that rows:

If ((pVal.FormType = 134 And pVal.EventType <> et_FORM_UNLOAD) And (pVal.Before_Action))

and

If ((pVal.EventType = et_FORM_LOAD) And (pVal.Before_Action = True))

I investigated that et_FORM_LOAD event has always pVal.Before_Action = false and pVal.BeforeAction = false

Just use that rows without pVal.Before_Action condition.

If so, the code works fine!

HTH!

Former Member
0 Kudos

Hi Aleksey,

thank your for your answer. I already searched the examples, but didn't find an answer. I'm using the example you mentioned to add the button to the form. This part works fine.

Furthermore I added a edittext field to the form, I can access the value of this field without any problem.

But I still have the question, how to get the value of a field, wich already exists on the form. In detail, I want to get the phonenumber(Item 43) from a businesspartner (form 134) and write this value into my textfield. I can access the value of my textfield by using the propterty "value" (myTextfield.value). But I don't know how to connect to the phonenumberfield correctly. I've tried some things with the items.item property, but every time, there isn't the propterty "value" avaiable. So I cant get the phonenumber out of the field and into my textfield.

Hopefully, you understand what I mean.

Thank you.

Tim Jaschik

Former Member
0 Kudos

Hi, Tim!

SAPbouiCOM.EditText edBPphone;

edBPphone = (SAPbouiCOM.EditText)oBPForm.Items.Item("43").Specific;

string BPphone = edBPphone.Value;

That's it! Maybe you didn't use "Specific" to get the object. oBPForm - Business_Partners form, you've got before.

HTH!