on 2020 Jun 09 5:07 PM
Hi.
I am trying to add credit card deposits using DI-API in SAP B1. I have a problem when adding multiple rows. What happens when I use my code is that it creates 2 deposits separately when I want to add 2 rows. If I have 3 rows, it adds 3 separate deposits of 1 row each.
How do I amend my code to fix this?
#region Use DIAPI to SAP
SAPbobsCOM.CompanyService oService = SboConnection.Company.GetCompanyService();
SAPbobsCOM.DepositsService dpService = (SAPbobsCOM.DepositsService)oService.GetBusinessService(SAPbobsCOM.ServiceTypes.DepositsService);
SAPbobsCOM.Deposit dpsAddMpesa = (SAPbobsCOM.Deposit)dpService.GetDataInterface(SAPbobsCOM.DepositsServiceDataInterfaces.dsDeposit);
dpsAddMpesa.DepositType = SAPbobsCOM.BoDepositTypeEnum.dtCredit;
SAPbobsCOM.DepositParams dpsParamAddMpesa;
SAPbobsCOM.CreditLines credits = dpsAddMpesa.Credits;
SAPbobsCOM.CreditLine credit;
dpsAddMpesa.DepositDate = DateTime.Now;
dpsAddMpesa.DepositAccountType = SAPbobsCOM.BoDepositAccountTypeEnum.datBankAccount;
dpsAddMpesa.DepositAccount = depositAcct;
dpsAddMpesa.VoucherAccount = deferredPmtAcct;
dpsAddMpesa.CommissionAccount = "SDR-06";
dpsAddMpesa.Commission = commission;
dpsAddMpesa.CommissionDate = DateTime.Now;
dpsAddMpesa.TaxCode = "X1";
dpsAddMpesa.DepositCurrency = "KES";
dpsAddMpesa.Project = "RETAIL";
dpsAddMpesa.DistributionRule = "GXD";
dpsAddMpesa.DistributionRule2 = "RETAIL";
dpsAddMpesa.JournalRemarks = "Added Mpesa Deposits with SAP B1 AddOn";
dpsAddMpesa.ReconcileAfterDeposit = SAPbobsCOM.BoYesNoEnum.tYES;
credit = credits.Add();
// Declare record set
SAPbobsCOM.Recordset rs = SboConnection.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
// Get AbsId
for (int i = 1; i <= oMatrix.VisualRowCount; i++)
{
string voucherNo = "";
int absId = 0;
// Get matrix voucher number
if (oMatrix.IsRowSelected(i) == true)
{
voucherNo = oMatrix.Columns.Item("1").Cells.Item(i).Specific.Value;
// Get absId
rs.DoQuery("SELECT T0.\"AbsId\" FROM OCRH T0 WHERE T0.\"VoucherNum\" = '" + voucherNo + "' AND T0.\"VoucherNum\" != 'No Ref Code'");
rs.MoveFirst();
int count = rs.RecordCount;
if (count > 0)
{
while (!rs.EoF)
{
absId = rs.Fields.Item("AbsId").Value;
rs.MoveNext();
}
}
credit.AbsId = absId;
dpsParamAddMpesa = dpService.AddDeposit(dpsAddMpesa);
}
}
#endregion
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
This is how I solved it.
Redid the code in the loop and got
dpsParamAddMpesa = dpService.AddDeposit(dpsAddMpesa);
out of the loop
#region Use DIAPI to SAP
SAPbobsCOM.CompanyService oService = SboConnection.Company.GetCompanyService();
SAPbobsCOM.DepositsService dpService = (SAPbobsCOM.DepositsService)oService.GetBusinessService(SAPbobsCOM.ServiceTypes.DepositsService);
SAPbobsCOM.Deposit dpsAddMpesa = (SAPbobsCOM.Deposit)dpService.GetDataInterface(SAPbobsCOM.DepositsServiceDataInterfaces.dsDeposit);
dpsAddMpesa.DepositType = SAPbobsCOM.BoDepositTypeEnum.dtCredit;
SAPbobsCOM.DepositParams dpsParamAddMpesa;
SAPbobsCOM.CreditLines credits = dpsAddMpesa.Credits;
SAPbobsCOM.CreditLine credit;
dpsAddMpesa.DepositDate = DateTime.Now;
dpsAddMpesa.DepositAccountType = SAPbobsCOM.BoDepositAccountTypeEnum.datBankAccount;
dpsAddMpesa.DepositAccount = depositAcct;
dpsAddMpesa.VoucherAccount = deferredPmtAcct;
dpsAddMpesa.CommissionAccount = "SDR-06";
dpsAddMpesa.Commission = commission;
dpsAddMpesa.CommissionDate = DateTime.Now;
dpsAddMpesa.TaxCode = "X1";
dpsAddMpesa.DepositCurrency = "KES";
dpsAddMpesa.Project = "RETAIL";
dpsAddMpesa.DistributionRule = "GXD";
dpsAddMpesa.DistributionRule2 = "RETAIL";
dpsAddMpesa.JournalRemarks = "Added Mpesa Deposits with SAP B1 AddOn";
dpsAddMpesa.ReconcileAfterDeposit = SAPbobsCOM.BoYesNoEnum.tYES;
// Declare record set
SAPbobsCOM.Recordset rs = SboConnection.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
// Get AbsId
for (int i = 1; i <= oMatrix.VisualRowCount; i++)
{
string voucherNo = "";
int absId = 0;
// Get matrix voucher number
if (oMatrix.IsRowSelected(i) == true)
{
voucherNo = oMatrix.Columns.Item("1").Cells.Item(i).Specific.Value;
// Get absId
rs.DoQuery("SELECT T0.\"AbsId\" FROM OCRH T0 WHERE T0.\"VoucherNum\" = '" + voucherNo + "' AND T0.\"VoucherNum\" != 'No Ref Code'");
rs.MoveFirst();
int count = rs.RecordCount;
if (count > 0)
{
while (!rs.EoF)
{
absId = rs.Fields.Item("AbsId").Value;
rs.MoveNext();
}
}
credit = dpsAddMpesa.Credits.Add();
credit.AbsId = absId;
}
}
dpsParamAddMpesa = dpService.AddDeposit(dpsAddMpesa);
#endregion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's Ok now. Figured out the mistake.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi kkjaykamauk,
It is always better to share how you managed to resolve the issue. This will help others if they come across the same problem.
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
| User | Count |
|---|---|
| 23 | |
| 12 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.