Skip to Content
Product Information
Author's profile photo ANKIT CHAUHAN

How to use “RecurringTransactionService” Object?

Starting from SAP Business One Version 9.2 PL05, you should be able to use “RecurringTransactionService” Object in order to perform the following:

  1. Get list of all available recurring transactions.
  2. Get information about particular recurring transaction.
  3. Remove set of recurring transactions.
  4. Execute set of recurring transactions.

This can be done following ways:

protected SAPbobsCOM.Company Comp = null;

protected SAPbobsCOM.CompanyService SrvCompany = null;

protected SAPbobsCOM.RecurringTransactionService SrvRecurringTransaction = null;


1. Get List of all available recurring transactions:

int result = 0;
int transID, templID;
SAPbobsCOM.RclRecurringTransactionCollection listAvailable = null;

try
{
    listAvailable = SrvRecurringTransaction.GetAvailableRecurringTransactions();

    foreach (SAPbobsCOM.IRclRecurringTransaction trans in listAvailable)
    {
        transID = trans.TransactionID;
        templID = trans.TemplateID;
    }
}
catch (Exception e)
{
    result = e.HResult;
}

2. Get Information about particular recurring transaction:

int result = 0;

SAPbobsCOM.RclRecurringTransactionParams paramsRT = null;
SAPbobsCOM.RclRecurringTransaction  rt = null;
SAPbobsCOM.RclRecurringTransactionStatusEnum    status;

try
{
    paramsRT = SrvRecurringTransaction.GetDataInterface(RecurringTransactionServiceDataInterfaces.rtsRclRecurringTransactionParams);
    paramsRT.TransactionID = rtAbsEntry;

    rt = SrvRecurringTransaction.GetRecurringTransaction(paramsRT);
    status = rt.Status;
}
catch (Exception e)
{
    result = e.HResult;
}

3. Remove/Delete set of recurring transaction:

protected int RemoveRT(HashSet<int> transToDelete)
{
int result = 0;

SAPbobsCOM.RclRecurringTransactionParamsparamRT = null;
SAPbobsCOM.RclRecurringTransactionParamsCollection  listRemoved = null;

try
{
    listRemoved = SrvRecurringTransaction.GetDataInterface(RecurringTransactionServiceDataInterfaces.rtsRclRecurringTransactionParamsCollection);

    foreach(int transID in transToDelete)
    {
        paramRT = listRemoved.Add();

        paramRT.TransactionID = transID;
    }

    SrvRecurringTransaction.DeleteRecurringTransactions(listRemoved);
}
catch (Exception e)
{
    result = e.HResult;
}
finally
{
    if (listRemoved != null)
    {
        Marshal.ReleaseComObject(listRemoved);
        listRemoved = null;
    }
}

return result;
}

4. Execute set of recurring transaction:

int result = 0;
    int cntAvailable, idxAvailable, id;

    SAPbobsCOM.RclRecurringTransactionParams paramsRT = null;
    SAPbobsCOM.RclRecurringTransactionParamsCollection paramsCollection = null;
    SAPbobsCOM.RclRecurringTransaction rt = null;
    SAPbobsCOM.RclRecurringTransactionCollection transactionsAvailable = null, transactionsOUT = null;
    SAPbobsCOM.RclRecurringExecutionParams paramsExec = null;

    try
    {
        paramsCollection = SrvRecurringTransaction.GetDataInterface(RecurringTransactionServiceDataInterfaces.rtsRclRecurringTransactionParamsCollection);
        paramsExec = SrvRecurringTransaction.GetDataInterface(RecurringTransactionServiceDataInterfaces.rtsRclRecurringExecutionParams);

        transactionsAvailable = SrvRecurringTransaction.GetAvailableRecurringTransactions();
        cntAvailable = transactionsAvailable.Count;

        // not all transactions from input parameter transToExec are available - execute only those which are available:
        for (idxAvailable = cntAvailable - 1; idxAvailable >= 0; --idxAvailable)
        {
           rt = transactionsAvailable.Item(idxAvailable);
           id = rt.TransactionID;

           if (transToExec.Contains(id))
           {
              paramsRT = paramsCollection.Add();
              paramsRT.TransactionID = id;
              if (id % 2 != 0)
              paramsRT.PlannedDate = DateTime.Now.Date;
           }
        }

        // if execution of one transaction fails, continue with next transaction execution
        paramsExec.OnError = RclRecurringExecutionHandlingEnum.rehSkipTransaction;

        transactionsOUT = SrvRecurringTransaction.ExecuteRecurringTransactions(paramsCollection, paramsExec);

        // show execution success/failure for particular transactions:
        foreach (RclRecurringTransaction trans in transactionsOUT)
        {
//DisplayInfo(String.Format("Transaction: {0}    Template: {1}    Status: {2}", trans.TransactionID, trans.TemplateID, trans.Status));
        }
    }
    catch (Exception e)
    {
        result = e.HResult;
        //Application.ShowStatus(this, Status, string.Format("    Exception {1}: {2}", Environment.NewLine, e.HResult, e.Message));
    }

Note: Creation of Recurring Transaction Template will still be done manually via SAP Business One Client.

 

 

Assigned tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Joerg Aldinger
      Joerg Aldinger

      Thank you vey much Ankit.

      Do you know if the recurring documents transactions (e.g. recurring invoices) are also exposed in the SDK or maybe even through Service Layer?

      Thank you,

      Joerg.

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Joerg,

      Thanks for pointing out!

      Please refer to screenshot above. DI API is supposed to perform actions as highlighted in the screenshot.

      But need to keep in mind that Recurring Transaction Templates will be created manually only.

      Kind regards,
      ANKIT CHAUHAN
      SAP SME Support

      Author's profile photo Leonardo Azevedo
      Leonardo Azevedo

      Thank's Ankit for your contribution.

      The creation of recurring transaction still remains manually via SAP B1?

      Regards,

       

      Leonardo.

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Leonardo Azevedo,

      Yes, as far as I have checked, creation of Recurring Transaction still remains manual.

      Refer to the following suggestion/idea on SAP Business One Customer Influence Site:

      https://influence.sap.com/sap/ino/#/idea/131299

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Leonardo Azevedo
      Leonardo Azevedo

      Hi Ankit,

      thank's once more for your rapid feedback.

      I hope this feature get come early, even with the Not planned status.

       

      Kind regards,

       

      Leonardo.

      Author's profile photo Kuldeep Kumar
      Kuldeep Kumar

      Hello Ankit,

      Good content. Nice to follow.