cancel
Showing results for 
Search instead for 
Did you mean: 

UDO (user defined object) and my form

Former Member
0 Kudos

Hello all,

I have a problems with UDO. I use SAP B1 2004C. I create table (object type = document) with two fields name,sname. I registred this table as UDO with id TES. Than i created a form this udo (no default form). This form has a matrix and two standard buttons. The matrix has two columns for filed name and sname. When i open the form i dont view my data in table. I cannot add new data. In table i have two lines, but in form i dont view this lines.

How can i make that i view data from UDO in my form? How can i make add new line after clic the button uid 1 "Add"?

The standard form for UDO has all functions, which i need on my form? How to make it?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

You will also need in your form:

Add a button with id = 1 for the Add/Update button. It will work automatically.

Add a button with id = 2 for the Cancel button. It will work automatically.

Add at the end BrowseBy = id of the edit text linked by a DbDataSource to the DocEntry field. To be able to use the navigation buttons (next, previous,...)

You must code by yourself the button to add a new line into the matrix.

Pay attention to the datas you create by yoursef (not using the UI) in the document/document_lines tables. They are releated by the DocEntry.

To test if it works fine please clear your tables and add the data from the UI form you have created. Maybe the datas you have entered by hand are not well formatted.

Regards

Trinidad.

Former Member
0 Kudos

Hello,

Thanks for your answers, but i tried everything and the form still doesnt have the same function. If it possible send me a sample with UDO and form designed for this form. Thanks.

Former Member
0 Kudos

Have u created a table of type "Document Lines".

Former Member
0 Kudos

Hello,

Yes i have the table with type Document and child table Documen lines. Why?

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

First of all I recommend you to remove all datas from your UDO tables.

Then try to create a simple form like the following one I give you the code.

In this first form there will be only 2 edit texts showing 2 user fields I have added to my Document table, and the 2 buttons Add/Update/Find and Cancel.

Remark: The button Add has nothing to do with adding a new line into the matrix representing the documents lines.

Here you have the creation of a form for a UDO:

'Creates an empty form

CP = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)

CP.FormType = "FrmDOC" ' Whatever you want

CP.ObjectType = "TT_DOC" 'UDO Object name

CP.UniqueID = "FDOC" ' Must be unique for each form you open

oFormDoc = SBO_Application.Forms.AddEx(CP)

oFormDoc.ClientWidth = 570

oFormDoc.ClientHeight = 400

' Add Edit Items

'BP(Code)

oItem = oFormDoc.Items.Add("txtBPCode", SAPbouiCOM.BoFormItemTypes.it_EDIT)

oItem.Left = 67

oItem.Top = 10

oItem.LinkTo = "lblBPCode"

'Binding

txtBPCode = oItem.Specific

txtBPCode.DataBind.SetBound(True, "@T_DOC", "U_BPCode")

' BP Name

oItem = oFormDoc.Items.Add("txtBPName", SAPbouiCOM.BoFormItemTypes.it_EDIT)

oItem.Left = 205

oItem.Top = 10

oItem.Width = 100

oItem.LinkTo = "lblBPName"

'Binding

txtBPName = oItem.Specific

txtBPName.DataBind.SetBound(True, "@T_DOC", "U_BPName")

' Adding Buttons

'* Create a Button to Support the Add ,Update, and Find Services

' ID must be "1" & no caption should be defined

oItem = oFormDoc.Items.Add("1", SAPbouiCOM.BoFormItemTypes.it_BUTTON)

oItem.Left = 6

oItem.Top = oFormDoc.ClientHeight - 24

oItem.Width = 65

oItem.Height = 18

oFormDoc.DefButton = "1"

' Add the Cancel button

oItem = oFormDoc.Items.Add("2", SAPbouiCOM.BoFormItemTypes.it_BUTTON)

oItem.Left = 77

oItem.Top = oFormDoc.ClientHeight - 25

oItem.Width = 65

oItem.Height = 20

'To make the navigation buttons work

oFormDoc.DataBrowser.BrowseBy = "txtBPCode"

Please tell me if this code works fine by replacing the UID of your UDO and the name of your document table on the edit texts binding. You should be able to add new items to your document table by using this form, also to use the find button (Ctrl+F to change the label on the form) and the navigation buttons (next, previous,...).

If it works fine then I can show you how to add the matrix representing the document lines table.

You have also a complete sample on how to create a form with a matrix on the SDK UDO samples. Please try to have a look at it.

Regards

Trinidad.

Former Member
0 Kudos

Hi,

I tried it and it is super. Can you tell me how to implement matrix to form. Thanks

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vit,

You only have to add a normal matrix and link its columns with your table of type Document_Lines.

To be able to enter information into the matrix lines you need to implement (for example) a button to add a line on the matrix and another to delete a line.

Here you have a sample:

oItem = oFormDoc.Items.Add("matrixDocLines", SAPbouiCOM.BoFormItemTypes.it_MATRIX)

oItem.Top = 50

oItem.Left = 10

oItem.Width = 300

oItem.Height = 200

oMatrixDoc1 = oItem.Specific

oColumns = oMatrixDoc1.Columns

'Add Columns to the matrix

'The # column

oColumn = oColumns.Add("#", SAPbouiCOM.BoFormItemTypes.it_EDIT)

oColumn.TitleObject.Caption = "#"

oColumn.Width = 20

oColumn.Editable = False

' ItemCode

oColumn = oColumns.Add("ItemCode1", SAPbouiCOM.BoFormItemTypes.it_EDIT)

oColumn.TitleObject.Caption = "ItemCode1"

oColumn.Width = 100

'Bind column

oColumn.DataBind.SetBound(True, "@T_DOC1", "U_ItemCode")

' ItemName

oColumn = oColumns.Add("ItemName1", SAPbouiCOM.BoFormItemTypes.it_EDIT)

oColumn.TitleObject.Caption = "ItemName 1"

oColumn.Width = 100

'Bind column

oColumn.DataBind.SetBound(True, "@T_DOC1", "U_ItemName")

' Add the AddRow button for Matrix

oItem = oFormDoc.Items.Add("AddRowDoc", SAPbouiCOM.BoFormItemTypes.it_BUTTON)

oItem.Left = 360

oItem.Top = 120

oButton = oItem.Specific

oButton.Caption = "Add Row"

You will need to capture the event et_ITEM_PRESSED on the AddRowDoc button and then add the row by hand.

Here you have a sample:

If ((pVal.FormTypeEx = "MyUDOFormType") And _

(pVal.ItemUID = "AddRowDoc") And _

(pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) And _

(pVal.BeforeAction = False)) Then

Dim ds As SAPbouiCOM.DBDataSource

ds = oFormMD.DataSources.DBDataSources.Item("@T_DOC")

'Clear the DataSources before adding a row

ds.Clear()

Dim count As Integer = oMatrixMD1.RowCount

'Add a new row

oMatrixMD1.AddRow(1, count)

'To have the cursor on the new line

oMatrixMD1.Columns.Item(1).Cells.Item(oMatrixMD1.RowCount).Click(SAPbouiCOM.BoCellClickType.ct_Regular)

After you make it work once please save it as Xml and then load the form using the class FormCreationParam by setting the property XmlData = string containing the xml information of your form.

Hope it works also fine

Regards

Trinidad.

Former Member
0 Kudos

Hi to everybody.

This conversation is very helpful for me. I was just trying to implement the same things.

But I've a question:

How can I use a custom form made by Screen Painter?

After the form is created by screen painter I load it by code (c#) and so I've not a FormCreationParams object where I can set the ObjectType property.

Can someone of you help me?

Thanks in advance,

Piero Cannizzaro

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

You can set the object type on your srf or xml file form properties.

You can also download an xml form by using the FormCreationParams object, you only have to fill the XmlData property to load it.

Regards

Trinidad.

Former Member
0 Kudos

Ok, I have also seen that in Screen Painter I can set the ObjectType property by the Form Property Panel. Thanks anayway.

Now I've tow questions:

1. I've created two custom tables by SAP B1 in order to manage master/details data. To do this I've chosen "Master Data"/"Master Data Lines" as types o my tables.

I've also added to these tables some custom fileds.

The question is: are the fields created automatically from SAP B1 in that tables managed from SAPB1 or I've to manage them by code?

2. How can I implement databinding (for each item on my custom form) by Screen Painter? Is possible?

Message was edited by: Piero Cannizaro

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Piero,

1.

The most part of the fields created automatically by B1 will be managed automatically by B1 you don't have to touch at them.

But some of them like Code and Name for MasterData should be entered by the user or by your code, B1 cannot create them for you.

2.

You have the properties DataBound, TableName and Alias for the items you can do databinding.

Regards

Trinidad.

Former Member
0 Kudos

Thanks a lot Trinidad.

I try it and I hope to be able to give you a positive feedback.

bye and thanks again!

Former Member
0 Kudos

Sorry Trinidad,

can you tell me how I've to use the properties DataBound, TableName and Alias?

I think the following:

1) In "TableName" I've to set the value indicating the name of my custom table (with "@" char at the beginning or without?)

2) In "DataBound" I've to set the name of the field contained in my table.

3) What value I've to set in "Alias" property???

Thanks

Piero

Former Member
0 Kudos

Hi Piero,

Databound must be set to true, tablename = @Table and Alias is your field name

Regards,

Adele

Former Member
0 Kudos

Thank you so much Adele!

Now the binding seems work fine.

Anyway I got an error adding a new record.

How I've to do to manage the "code" and "name" fields by code? I think the error I got depends on management of these fields.

Former Member
0 Kudos

what is the error you're getting and where in your code does it happen?

Former Member
0 Kudos

There aren't errors in my code.

The error is raised why the table's field "Code" is empty.

I resolved the problem putting a hidden EDIT Field on my custom form binded with "Code" field and pupulate it by code. Now all the logic works very well.

Thanks anayway

Piero

p.s. Now I try to bind the matrix to handle the details data. Let's wish me good luck!

Former Member
0 Kudos

Hi Trinidad,

I'm tryng to handle the following operations on my matrix:

1)add a new row

2)delete a row

In order to do this I was reading your post on this topic where you write the following:

-


If ((pVal.FormTypeEx = "MyUDOFormType") And _

(pVal.ItemUID = "AddRowDoc") And _

(pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) And _

(pVal.BeforeAction = False)) Then

Dim ds As SAPbouiCOM.DBDataSource

ds = oFormMD.DataSources.DBDataSources.Item("@T_DOC")

'Clear the DataSources before adding a row

ds.Clear()

Dim count As Integer = oMatrixMD1.RowCount

'Add a new row

oMatrixMD1.AddRow(1, count)

'To have the cursor on the new line

oMatrixMD1.Columns.Item(1).Cells.Item(oMatrixMD1.RowCount).Click(SAPbouiCOM.BoCellClickType.ct_Regular)

-


The question is:

Why you add a DbDataSource (bound with your Master table) to the form??

Which is the reason? I've seen you don't use it.

Can you explain it to me?

Thanks in advance!

Piero

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

When you create a form to link with a UDO you must bind all the static texts and matrix columns to their corresponding TableName - Alias.

To be able to use a TableName you must first add to the form a DBDataSource containing the TableName.

In the button Add I only look for the DBDataSource of the matrix an clear it before adding the row, if you don't do it then the last line is copied in the new added one and you have problems to save the record.

ds = oFormMD.DataSources.DBDataSources.Item("@T_DOC")

ds.Clear()

Regards

Trinidad.

Former Member
0 Kudos

ok. In C# I use this code:

-


if (ie.ItemUID == "cmdAddRow")

{

SAPbouiCOM.DBDataSource dbDs = FormHandle.DataSources.DBDataSources.Item("@DSLAT"); // DSLAT is my MasterData table

dbDs.Clear();

mx.AddRow(1, mx.RowCount);

mx.Columns.Item(1).Cells.Item(mx.RowCount).Click(SAPbouiCOM.BoCellClickType.ct_Regular, 0);

}

else if (ie.ItemUID == "cmdDelRow")

{

int selectedRowIndex = mx.GetNextSelectedRow(0, SAPbouiCOM.BoOrderType.ot_RowOrder);

if (selectedRowIndex > -1)

{

mx.DeleteRow(selectedRowIndex);

}

else

MessageBoxToSAP("No rows selected"); //this is a custom method

}

-


Adding a new row the code above work fine.

Updating or Deleting a row the code NOT work fine!

In details the code delete the row from the matrix but the changes are not applied to database.

The same happens attempting to update a row.

Could you show me an example of how this code should be implemented?

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

The implementation seems correct.

Once you click on the Del button, does the button Ok change to Update?

If it changes to update and you press Update is the line removed if you search for this record?

Are you working with the 2004 or 2005 version?

Former Member
0 Kudos

Once I click on the Del button the row is removed from the matrix but the default button (with UniqueID=1) doesn't change to Update! So if I click on the Ok button the form close itself

p.s. I'm working with 2005 version.

What can I do?

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Please try to set the mode to update after removing or adding a line:

if (form.Mode != BoFormMode.fm_ADD_MODE)

form.Mode = BoFormMode.fm_UPDATE_MODE;

Regards

Trinidad.

FOA
Advisor
Advisor
0 Kudos

Hi Piero,

I'm not sure what you are asking in your first question. Do you mean fields Code and Name? That are created automatically by B1? Once you had defined your own Tables and you linked your UDO to them, you dont have to do more than going through the Wizard or to indicate which fields are going to be visible (in case you select "Default Form").

Q2. You can bound data in the screen painter by selecting the field, then the "Items Tab" then in the "Specific" section you will give the "Alias" (name of the field in the DB), the "Databound" set to "true", and in "TableName" the name of the table that contains this field.

Hope this helps,

Felipe

Former Member
0 Kudos

hi Trinidad,

i have written the same code to me it gives error 'The Server Trew an exception' and if i remove ds.clear it works fine

but then the record is not added on the click of ADD

Do u know the reason why

Former Member
0 Kudos

hi saranraj,

how to get the object type name.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Vit Nemec

When u r creating a form there is a property of form "ObjectType" u have to give your UDO name there and bound all the files to the controls

u will get all the functionaly on yr form

Thanks

Ankush VACHHER

Former Member
0 Kudos

Hello all,

i tried it, but it doesnt help to me. I made new form in Screen painter and to property ObjectType assigned UDO id. But the form doesnt have a function as standard form for UDO. Can you send me some example where is form (from Screen painter) for UDO?

Thanks

Former Member
0 Kudos

First check weather u have registered ur UDO or not.

At the moment u r adding new object, u have to assign a "Unique Id" in

the registration Wizard.

Use this id in your XML.

In the XML put this id in ObjectType=""

Add the datasources to your form.

Add the tables and alises in your form.

Former Member
0 Kudos

On the SDK documentation there's an example called Matrix&Data Sources. This should be very helpful.