Create Button to add all RMA Lines to a credit note

Hi,

I have created a button within RMA Processing which i would like to cycle through all Lines in the RMA Dtl and add them to the credit note rather than do it line by line.

I can get it to work but i have to specify the RMA Num and RMA Line in the code to have the button add the Line to the Credit Note.

Current code is below which adds 1 line if I replace iRMANum, iRMALine with 27,1

This is E9  code on Button click events which loops through all RMA lines.
private void EBProcessCredits_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
          EpiDataView edvRMADtl = ((EpiDataView)(this.oTrans.EpiDataViews["RMADtl"]));
          for (int i = 0; i < edvRMADtl.dataView.Table.Rows.Count; i++)
	  {
          	int lRMANum = Convert.ToInt32(edvRMADtl.dataView.Table.Rows[i]["RMANum"])  ;
          	int lRMALine = Convert.ToInt32(edvRMADtl.dataView.Table.Rows[i]["RMALine"])  ;
           	bool recSelected;
           	string whereClause = "RMANum = '" + lRMANum + "' and RMALine = '" + lRMALine + "'" ;;
		System.Data.DataSet dsARInvcDtlSearchAdapter = Epicor.Mfg.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "ARInvcDtlSearchAdapter", out recSelected, false, whereClause);
		if (recSelected)
		{
                }
               else
              {
                CallRMAProcAdapterRMACreditAddMethod(lRMANum, lRMALine);
              }
          }
          oTrans.Refresh();
	}

@Arul Nothing is happening when i click the button after putting this code in.
See below full code:

// **************************************************
// Custom code for RMAProcForm
// Created: 12/05/2021 10:04:28
// **************************************************

extern alias Erp_Adapters_SalesOrder;

extern alias Erp_Contracts_BO_RMAProc;
extern alias Erp_Contracts_BO_SalesOrder;
extern alias Erp_Contracts_BO_Customer;
extern alias Erp_Contracts_BO_ShipTo;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_OrderRelSearch;
extern alias Erp_Adapters_RMAProc;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

public class Script
{
// ** Wizard Insert Location - Do Not Remove ‘Begin/End Wizard Added Module Level Variables’ Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
	// Begin Wizard Added Variable Initialization

	// End Wizard Added Variable Initialization

	// Begin Wizard Added Custom Method Calls


	// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
	// Begin Wizard Added Object Disposal


	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal

	// End Custom Code Disposal
}

private void CallRMAProcAdapterRMACreditAddMethod(int lRMANum, int lRMALine)
{
try
{
// Declare and Initialize EpiDataView Variables
// Declare and create an instance of the Adapter.
RMAProcAdapter adapterRMAProc = new RMAProcAdapter(this.oTrans);
adapterRMAProc.BOConnect();

	// Declare and Initialize Variables
	bool iCorrection = false;
	Int32 iInvoiceNum = 0;
	Int32 iInvoiceLine = 0;
	string opErrMsg = string.Empty;

	// Call Adapter method
             adapterRMAProc.GetByID(lRMANum);
 
	bool result = adapterRMAProc.RMACreditAdd(lRMANum, lRMALine, iCorrection, out iInvoiceNum, out iInvoiceLine, out opErrMsg);
                 adapterRMAProc.Update();
	// Cleanup Adapter Reference
	adapterRMAProc.Dispose();

} catch (System.Exception ex)
{
	ExceptionBox.Show(ex);
}

}

private void btn_CreateCreditNote_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
EpiDataView edvRMADtl = ((EpiDataView)(this.oTrans.EpiDataViews[“RMADtl”]));
for (int i = 0; i < edvRMADtl.dataView.Table.Rows.Count; i++)
{
int lRMANum = Convert.ToInt32(edvRMADtl.dataView.Table.Rows[i][“RMANum”]) ;
int lRMALine = Convert.ToInt32(edvRMADtl.dataView.Table.Rows[i][“RMALine”]) ;
bool recSelected;
string whereClause = “RMANum = '” + lRMANum + “’ and RMALine = '” + lRMALine + “’” ;;
System.Data.DataSet dsARInvcDtlSearchAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, “ARInvcDtlSearchAdapter”, out recSelected, false, whereClause);
if (recSelected)
{
}
else
{
CallRMAProcAdapterRMACreditAddMethod(lRMANum, lRMALine);
}
}
oTrans.Refresh();
}
}

@Ricky90 This code is working? Is one-click all lines are creating?