on 06-02-2011 11:43 AM
Dear,
I want to use the "UpdateDistributionRule" method for updating (add new line) the existing distribution rules. I have tried the code from SDK help, but it does not work.
Here is the code from SDK help as below:
oCmpSrv = oCompany.GetCompanyService()
Dim oDLservice As SAPbobsCOM.DistributionRulesService = oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.DistributionRulesService)
Dim oDL As SAPbobsCOM.DistributionRule
Dim oDLParams As SAPbobsCOM.IDistributionRuleParams
' Get distribution rule
oDLParams = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRuleParams)
oDLParams.FactorCode = "1"
Try
oDL = oDLservice.GetDistributionRule(oDLParams)
Catch ex As Exception
MsgBox(ex.Message)
End Try
' Update distribution rule
oDL = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRule)
oDL.FactorCode = "1"
oDL.FactorDescription = "Desc 1"
oDL.InWhichDimension = 1
oDL.TotalFactor = 40
oDL.DistributionRuleLines.Add()
oDL.DistributionRuleLines.Item(0).CenterCode = "1"
oDL.DistributionRuleLines.Item(0).TotalInCenter = "10"
oDL.DistributionRuleLines.Add()
oDL.DistributionRuleLines.Item(1).CenterCode = "2"
oDL.DistributionRuleLines.Item(1).TotalInCenter = "30"
Try
oDLservice.UpdateDistributionRule(oDL)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Regards,
On
What does "it does not work" mean? Do you get an error? Does nothing happen?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK maybe it is the usual SAP error where there already exists an item in the collection, so it thinks you are trying to add 3 lines and not 2.
Try changing it to this:
' Update distribution rule
oDL = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRule)
oDL.FactorCode = "1"
oDL.FactorDescription = "Desc 1"
oDL.InWhichDimension = 1
oDL.TotalFactor = 40
'The first DistributionRuleLine already exists an is empty so you just need to populate it
'so remove the first oDL.DistributionRuleLines.Add()
oDL.DistributionRuleLines.Item(0).CenterCode = "1"
oDL.DistributionRuleLines.Item(0).TotalInCenter = "10"
oDL.DistributionRuleLines.Add()
oDL.DistributionRuleLines.Item(1).CenterCode = "2"
oDL.DistributionRuleLines.Item(1).TotalInCenter = "30"
This is the same way that subobject collections work throughout the DI API - for example it is the same for Document_Lines object. The error is coming because it think the first line is empty, and then you add two more lines and populate them.
Maybe the helpfile is just wrong with its example?
HI,
Tried, but not work.
It shows - Invalid row number
Also, I try another like the following, but not work.
It shows - Enter valid amount in "Total"
Dim oCmpSrv As SAPbobsCOM.CompanyService
oCmpSrv = oCompany.GetCompanyService()
Dim oDLservice As SAPbobsCOM.DistributionRulesService = oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.DistributionRulesService)
Dim oDL As SAPbobsCOM.DistributionRule
Dim oDLParams As SAPbobsCOM.IDistributionRuleParams
' Get distribution rule
oDLParams = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRuleParams)
oDLParams.FactorCode = "DR001"
Try
oDL = oDLservice.GetDistributionRule(oDLParams)
' Update distribution rule
oDL.FactorCode = "DR001"
oDL.FactorDescription = "Desc 1"
oDL.InWhichDimension = 1
oDL.TotalFactor = 60
oDL.DistributionRuleLines.Item(0).CenterCode = "036" -> exist line
oDL.DistributionRuleLines.Item(0).TotalInCenter = "20"
oDL.DistributionRuleLines.Item(1).CenterCode = "049" -> exist line
oDL.DistributionRuleLines.Item(1).TotalInCenter = "30"
oDL.DistributionRuleLines.Add()
oDL.DistributionRuleLines.Item(2).CenterCode = "090" -> new line
oDL.DistributionRuleLines.Item(2).TotalInCenter = "10"
Try
oDLservice.UpdateDistributionRule(oDL)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Catch ex As Exception
MsgBox(ex.Message)
End Try
Regards,
On
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.