on 01-31-2012 2:19 PM
Hi!
I need to create a MANUAL distribution rule from the SDK to associate then with a line of an Invoice.
I've already used the object SAPbobsCOM.DistributionRule but when I add is displayed in the master data of the distribution rules, in this way:
Dim oCmpSrv As SAPbobsCOM.CompanyService = oCompany.GetCompanyService()
Dim oDLservice As SAPbobsCOM.DistributionRulesService = oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.DistributionRulesService)
Dim oDL As SAPbobsCOM.DistributionRule
' Add distribution rule
oDL = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRule)
oDL.FactorCode = _Code
oDL.FactorDescription = _Code
oDL.InWhichDimension = 1
Dim TotalFactor As Double = 0
For i As Integer = 0 To (ProfitCenters.Length \ 2) - 1
oDL.DistributionRuleLines.Add()
oDL.DistributionRuleLines.Item(i).CenterCode = ProfitCenters(i, 0)
oDL.DistributionRuleLines.Item(i).TotalInCenter = ProfitCenters(i, 1)
oDL.DistributionRuleLines.Item(i).Effectivefrom = Date.Now
TotalFactor += ProfitCenters(i, 1)
Next
oDL.TotalFactor = TotalFactor
Try
oDLservice.AddDistributionRule(oDL)
Catch ex As Exception
oLog.Errore(ex.Message, ex)
_return = ""
End Try
I would use a manual distribution rule.
How can I do?
Thanks!
Hi. Did you find any solution to post the data to manual distribution rule using DIAPI.?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I have succeeded.
I attach a example code :
oSapInvoice.Lines.CostingCode = AddDistributionRule(ProfitCenters, LineTotal, Me.DocDestDataDoc)
where:
Public Function AddDistributionRule(ByVal ProfitCenters(,) As String, ByVal LineTotal As Double, ByVal DocDate As Date) As String
Dim _return As String = ""
Dim oCmpSrv As SAPbobsCOM.CompanyService = oCompany.GetCompanyService()
Dim oDLservice As SAPbobsCOM.DistributionRulesService = oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.DistributionRulesService)
Dim oDL As SAPbobsCOM.DistributionRule
Dim recordSet As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
Dim sSQL As String
recordSet.DoQuery("SELECT ISNULL(MAX(CAST(SUBSTRING(OcrCode,2,8) AS INTEGER)),0) FROM OOCR WHERE OcrCode LIKE 'H%'")
Dim maxIndex As Integer
If recordSet.Fields.Item(0).Value.ToString = "" Then
maxIndex = 1
Else
maxIndex = Integer.Parse(recordSet.Fields.Item(0).Value.ToString)
maxIndex += 1
End If
Dim sCode As String = maxIndex.ToString("0000000")
_return = "H" & sCode
' Add distribution rule
oDL = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRule)
oDL.FactorCode = _return
oDL.FactorDescription = _return
oDL.InWhichDimension = 1
Dim TotalFactor As Double = 0
Dim TotaleKM As Double = 0
For i As Integer = 0 To (ProfitCenters.Length \ 2) - 1
TotaleKM += ProfitCenters(i, 1)
Next
Dim j As Integer = 0
For i As Integer = 0 To (ProfitCenters.Length \ 2) - 1
If CDbl(ProfitCenters(i, 1)) > 0 Then
Dim KM As Double = ProfitCenters(i, 1)
Dim Ricavo As Double = (KM * LineTotal) / TotaleKM
oDL.DistributionRuleLines.Add()
oDL.DistributionRuleLines.Item(j).CenterCode = ProfitCenters(i, 0)
oDL.DistributionRuleLines.Item(j).TotalInCenter = Ricavo
oDL.DistributionRuleLines.Item(j).Effectivefrom = DocDate
j += 1
TotalFactor += Ricavo
End If
Next
oDL.TotalFactor = TotalFactor
Try
oDLservice.AddDistributionRule(oDL)
Catch ex As Exception
oLog.Errore(ex.Message, ex)
_return = ""
End Try
Return _return
End Function
Hi Gianluca
I have tried it but am facing the below issue
540000077 - You cannot continue; distribution rule is not fully within linked cost center's effective period
at oDLservice.AddDistributionRule(oDL).
cost centers are effective from 01-01-2014 to 31-12-2014
and am passing the DocDate as today's date.
Hi Gianluca
Above issue is resolved. The Distributions are added in OOCR and are not getting assigned to the Dimension 1 Cost center.
I have tried the same that you have suggested.
Do you have any other idea?
Hi Gianluca
Thank you. There was an error in my code.. your solution works. But the distribution rule is added to OOCR.
Is there no other way to add the disribution rule to OMDR.
Hi,
What is the reason you select: (ProfitCenters.Length \ 2) - 1 as the ending point?
Thanks,
Gordon
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 | |
9 | |
9 | |
5 | |
4 | |
3 | |
3 | |
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.