cancel
Showing results for 
Search instead for 
Did you mean: 

Problem when update distribution rules by "UpdateDistributionRule" method

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

What does "it does not work" mean? Do you get an error? Does nothing happen?

Former Member
0 Kudos

Hi,

Cannot add line and the error message is

Enter valid amount in "Total"

More, there has no "Delete" function for delete line.

Regards,

On

Former Member
0 Kudos

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?

Former Member
0 Kudos

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

Former Member
0 Kudos

I think you need to contact SAP support then - if the sample from the helpfile doesn't work, then it would seem it could be a bug, or the help file doesn't explain it well enough for us to understand