cancel
Showing results for 
Search instead for 
Did you mean: 

Add Items using DI-API

Former Member
0 Kudos

HI All,

How to add an item & its details into the SAP db using DI-API(in vb.net).....can anybody give me the coding pls...

regards,

shangai.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Shangai,

When you install the Business One SDK, you install both the help centre and the samples automatically.

The help centre can be found in Start->Programs->SAP Business One->SDK->SDK Help Centre. The samples can be found in the same path.

In the help centre, there are several examples available - for example, I have copy and pasted this from the help centre:


Sub Add_Item()
Dim RetVal As Long
    Dim ErrCode As Long
    Dim ErrMsg As String
    Dim vItem As SAPbobsCOM.Items

    Set vItem = vCmp.GetBusinessObject(oItems)
    'Set value to mandatory fields:
    vItem.ItemCode = "MyNewItem"
    'Set Value to other fields
    vItem.ItemName = "MyNewItem Name"
    vItem.WhsInfo.WarehouseCode = "01"
    'Adding the Item
    RetVal = vItem.Add
    'Checking the result
    If RetVal <> 0 Then
        vCmp.GetLastError ErrCode, ErrMsg
        MsgBox ErrCode & " " & ErrMsg
    End If
 End Sub

Additionally, the help centre lists every object, method and property including what values are valid, what fields are Mandatory and covers both UI and DI.

The samples are a great resource too for learning the ins and outs of the Business One SDK.

Hope this helps.

Regards

Niall

SAP Business One Forums Team

Former Member
0 Kudos

Hi Nial,

In this below code what should i declare for 'oItems'


Set vItem = vCmp.GetBusinessObject(oItems)

Former Member
0 Kudos

Hi shangai,

"oItems" is a BoObjectTypes object type.

So the code is :

vCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)

Regards

Michael

Former Member
0 Kudos

hi micheal,

thanks a lot it solved my problem...i have given full points.

regards,

shangai.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Experts,

using DI API iam adding items in item master data...like the below code i want to add the currency,Pricelistcode,pricelist but iam unable to find those properties.....can anybody help me...

 
 vItem.ItemName = "MyNewItem Name"

regards,

shangai.

Edited by: shangai Nights on Sep 4, 2008 5:41 PM

Former Member
0 Kudos

Hi Shangai,

those properties are in the PriceList Child Object of the ItemMaster:

 vItem.ItemName = "MyNewItem Name"
 vItem.PriceList.SetCurrentLine( "YourPriceListLine") // it will depends on how many pricelists do you have.
 vItem.PriceList.Price = "YourPrice"
 vItem.PriceList.Add()

Hope it helps!

Marta

Former Member
0 Kudos

hi marta,

Thanks for ur reply...it's work fine...i have a doubt in this


   vItem.PriceList.PriceListName=""

iam unable to add any value...because it's aread only one....how to add the price list name then???

regards,

shangai.

Nussi
Active Contributor
0 Kudos

Hi,

in the item you have automatically all pricelists.

you don't place the name there.

important is just that you place the line correct.

oItems.PriceList.SetCurrentLine(i)

(be aware that the i starts with 0)

look if the name is the correct name and than set the price

oItems.PriceList.Price

lg David

Former Member
0 Kudos

Hi Shangai,

You don't need to add the PriceListName. All Items have automatically all the PriceLists. (The PriceLists are defined in Inventory/PriceLists/PriceLists.)

With vItem.PriceList.SetCurrentLine( "YourPriceListLine") you are selecting the PriceList to add your price. You can use this value to check that your are takking the correct PriceList.

You can add different prices for the different PriceLists.

dim NLists as integer

NLists = vItem.PriceList.count

for IDlist as integer = 0 to (NLists -1)
vItem.PriceList.SetCurrentLine(IDlist) 

if "SALES" = vItem.PriceList.PriceListName then
vItem.PriceList.Price = "your sales price" 

else if  "PURCHASE" = vItem.PriceList.PriceListName then
vItem.PriceList.Price = "your purchase price" 
end if

next

You will have always two lists thar are automatically filled by the system:

- Last Purchase Price

- Last Evaluated Price

Hope it helps!

Marta

Former Member
0 Kudos

Hi,

thanks a lot....your coding works fine....but i have one small doubt in this......while adding items through DI-API in item master data iam able to add item code,item name...etc but if i want to add a new ItemGroup & Manufacturer...then how can i create new one(Define New) & add...


vItem.ItemsGroupCode = Sample Group    

When i give vItem.ItemsGroupCode = 100 &

vItem.Manufacturer=1 then it's taking the default type based on cobobox index but i want to create a new item group in the front end itself...

Regards,

Shangai.

Nussi
Active Contributor
0 Kudos

Shanghai,

for creating itemgroups you use another object:

ItemGroups Object

in oItem.ItemsGroupCode you set only itemgroups that already exist.

so create the group first than set it in your item.

lg David

Former Member
0 Kudos

hi david,

How to create the item group before Item group code?????...iam unable to find Item Groups object for my oItems...

regards,

shangai.

Former Member
0 Kudos

Hi Shangai,

the ItemGroups object is not an Item object.

You need to retrieve the ItemGroups directly:

dim oItemGroups as SAPbobsCOM.ItemGroups
oItemGroups = vcmp.getBusinessObject(SAPbobsCOM.BoObjectTypes.oItemGroups)
oItemGroups.GroupName= "Your new group name"
oItemGroups.add()

The code is set automatically by SBO when you insert the new ItemGroup.

oItemGroups.Number

Hope it helps.

Marta

Former Member
0 Kudos

hi,

it's work fine....then similar to that i have created for adding new manufacturers also......thanks a lot marta....

Regards,

shangai.

Former Member
0 Kudos

Hi,

I guess u could use the following code....

Dim oitem As SAPbobsCOM.Items
                        oitem = SBO_Appln.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
                        oitem.ItemCode = ""
                        oitem.ItemName = ""
                        oitem.ItemType = SAPbobsCOM.ItemTypeEnum.itItems
                        oitem.Add()

hope it helps..

Regards,

Vasu Natari.

Former Member
0 Kudos

Hi micheal & vasu...

thanks for ur replies.....i try ur codings.

regards,

shangai.

Former Member
0 Kudos

Hi shangai,

This is an example to add an item with DI API :

Dim RetVal As Long

Dim ErrCode As Long

Dim ErrMsg As String

Dim vItem As SAPbobsCOM.Items

Set vItem = vCmp.GetBusinessObject(oItems)

'Set value to mandatory fields:

vItem.ItemCode = "MyNewItem"

'Set Value to other fields

vItem.ItemName = "MyNewItem Name"

vItem.WhsInfo.WarehouseCode = "01"

'Adding the Item

RetVal = vItem.Add

'Checking the result

If RetVal <> 0 Then

vCmp.GetLastError ErrCode, ErrMsg

MsgBox ErrCode & " " & ErrMsg

End If

Regards

Michael