on 07-02-2004 2:02 PM
Hi all,
I want to create new Item based on existing Item in the database. Of course the new Item has unique ItemCode and many others fields (for example, I have main item and its variants with differences in UDF's).
My code:
Dim oItem As SAPbobsCOM.Items
Dim oMainItem As SAPbobsCOM.Items
Set oItem = oCompany.GetBusinessObject(oItems)
Set oMainItem = oCompany.GetBusinessObject(oItems)
oMainItem.GetByKey (sMainCode)
Set oItem = oMainItem
oItem.ItemCode = sCode
oItem.ItemName = sName
oItem.UserFields.Fields.Item("U_farbe").Value = ColorName
oItem.UserFields.Fields.Item("U_hauptArt").Value = ArtikelNr
oItem.UserFields.Fields.Item("U_artNr").Value = FedasCode
If oItem.Add <> 0 Then
oCompany.GetLastError ErrCode, ErrMsg
MsgBox ErrCode & " " & ErrMsg
End If
Method Add() always returns this error:
"-5002 Invalid Code [OITW.WhsCode] , 'Main_45_sjdgj '"
Can anyone help?
Thanks
Libor Mego.
Hi all,
I have found some solution of this problem, but isn't very nice 🐵
Dim oItem As SAPbobsCOM.Items
Dim oMainItem As SAPbobsCOM.Items
dim lPriceList, lWhsInfo as Long
Set oItem = oCompany.GetBusinessObject(oItems)
Set oMainItem = oCompany.GetBusinessObject(oItems)
oMainItem.GetByKey (sMainCode)
'// first copy PriceList info
For lPriceList = 0 To oMainItem.PriceList.count - 1
oMainItem.PriceList.SetCurrentLine (lPriceList)
oItem.PriceList.SetCurrentLine (lPriceList)
oItem.PriceList.Currency = oMainItem.PriceList.Currency
oItem.PriceList.Price = oMainItem.PriceList.Price
Next lPriceList
'// second copy Warehouse info
For lWhsInfo = 0 To oMainItem.WhsInfo.count - 1
oMainItem.WhsInfo.SetCurrentLine (lWhsInfo)
oItem.WhsInfo.Add
oItem.WhsInfo.SetCurrentLine (lWhsInfo)
oItem.WhsInfo.CostAccount = oMainItem.WhsInfo.CostAccount
oItem.WhsInfo.DecreasingAccount = oMainItem.WhsInfo.DecreasingAccount
oItem.WhsInfo.EUExpensesAccount = oMainItem.WhsInfo.EUExpensesAccount
oItem.WhsInfo.EURevenuesAccount = oMainItem.WhsInfo.EURevenuesAccount
oItem.WhsInfo.ExemptIncomeAcc = oMainItem.WhsInfo.ExemptIncomeAcc
oItem.WhsInfo.ExpensesAccount = oMainItem.WhsInfo.ExpensesAccount
oItem.WhsInfo.ForeignExpensAcc = oMainItem.WhsInfo.ForeignExpensAcc
oItem.WhsInfo.ForeignRevenueAcc = oMainItem.WhsInfo.ForeignRevenueAcc
oItem.WhsInfo.IncreasingAccount = oMainItem.WhsInfo.IncreasingAccount
oItem.WhsInfo.InventoryAccount = oMainItem.WhsInfo.InventoryAccount
oItem.WhsInfo.MaximalStock = oMainItem.WhsInfo.MaximalStock
oItem.WhsInfo.MinimalOrder = oMainItem.WhsInfo.MinimalOrder
oItem.WhsInfo.MinimalStock = oMainItem.WhsInfo.MinimalStock
oItem.WhsInfo.PriceDifferenceAcc = oMainItem.WhsInfo.PriceDifferenceAcc
oItem.WhsInfo.ReturningAccount = oMainItem.WhsInfo.ReturningAccount
oItem.WhsInfo.RevenuesAccount = oMainItem.WhsInfo.RevenuesAccount
oItem.WhsInfo.StandardAveragePrice = oMainItem.WhsInfo.StandardAveragePrice
oItem.WhsInfo.TransferAccount = oMainItem.WhsInfo.TransferAccount
oItem.WhsInfo.VarienceAccount = oMainItem.WhsInfo.VarienceAccount
oItem.WhsInfo.WarehouseCode = oMainItem.WhsInfo.WarehouseCode
Next lWhsInfo
'// and at least copy all the necessary simple fields you need to replicate from MainItem to your new Item (there are lots of them)
oItem.BarCode = oMainItem.BarCode
oItem.AssetItem = oMainItem.AssetItem
oItem.ItemsGroupCode = oMainItem.ItemsGroupCode
You can see, it isn't very nice, but functional.
Regards
Libor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Yaniv,
thanks for your reply.
But, when I need my new Item with the same data in the fields like my Main Item, with differences only in ItemCode, ItemName and a few UDF, should I make it manually? For Example my code:
oItem.AssetItem = oMainItem.AssetItem
oItem.AvgStdPrice = oMainItem.AvgStdPrice
oItem.BarCode = oMainItem.BarCode
oItem.CommissionGroup = oMainItem.CommissionGroup
oItem.CommissionPercent = oMainItem.CommissionPercent
oItem.CommissionSum = oMainItem.CommissionSum
oItem.CustomsGroupCode = oMainItem.CustomsGroupCode
oItem.DataExportCode = oMainItem.DataExportCode
oItem.DefaultWarehouse = oMainItem.DefaultWarehouse
oItem.DesiredInventory = oMainItem.DesiredInventory
oItem.ECExpensesAccount = oMainItem.ECExpensesAccount
oItem.ECRevenuesAccount = oMainItem.ECRevenuesAccount
oItem.ExemptIncomeAccount = oMainItem.ExemptIncomeAccount
oItem.ExpanseAccount = oMainItem.ExpanseAccount
oItem.ForceSelectionOfSerialNumber = oMainItem.ForceSelectionOfSerialNumber
oItem.ForeignExpensesAccount = oMainItem.ForeignExpensesAccount
oItem.ForeignName = oMainItem.ForeignName
oItem.ForeignRevenuesAccount = oMainItem.ForeignRevenuesAccount
oItem.Frozen = oMainItem.Frozen
oItem.FrozenFrom = oMainItem.FrozenFrom
oItem.FrozenRemarks = oMainItem.FrozenRemarks
oItem.FrozenTo = oMainItem.FrozenTo
oItem.GLMethod = oMainItem.GLMethod
...
There are too many fields. And what happend, when in next version of SBO or SDK for example new fields or new business objects comes or field-names will change?
Thanks for reply.
Regards
Libor Mego.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One feature that I would like to see, that would help toward a solution would be the abilities to access properties with text names and the ability to iterate over the properties.
Perhaps the code might look like this:
for each sProp in oMainItem.Properties
oNewItem.Properties(sProp) = oMainItem.Properties(sProp)
next sProp
I would like the properties to be referenced via strings so that I could allow the user to create configuration lists of properties that they want to use, perhaps in an export.
We already have a similar capability for user fields.
Hi,
In your code - the line <i>Set oItem = oMainItem</i> means you're pointing to the same instance with two objects. You cannot use this coding in order to "copy" Items.
Since the is an auto-complete module,
You can copy the data inside the properties.
copy only the desired data and then add the <b>new</b> item.
example:
oItem.Manufacturer = oMainItem.Manufacturer
oItem.PriceList = oMainItem.PriceList
Regards
Yaniv G.
SDK Consultant,
SAP Manage Israel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
99 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.