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.RclRecurringTransactionParams            paramRT = 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.

 

 

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. 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.

    (0) 
  2. ANKIT CHAUHAN 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

    (0) 

Leave a Reply