Paste the following script in the script editing window:
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName == "InsertRecordToTBC")
{
var currentBC;
var currentTBC;
var currentBO;
var isSuccess;
var iCounter;
var indata;
var isRecord;
currentBO = TheApplication().GetBusObject ("Opportunity");
currentTBC = currentBO.GetBusComp ("TBUI81MultiRecordTBC");
currentBC = currentBO.GetBusComp ("Opportunity");
//Inserts data in the TBC
iCounter = 3;
do
{
indata="OptyMTBC"+iCounter;
currentTBC.NewRecord(0); // creating a new record
currentTBC.SetFieldValue("OptyName", indata); //setting name field
currentTBC.WriteRecord(); // writing record in the multirecord TBC
iCounter--;
} while(iCounter);
//Get the data from TBC and insert in BC
currentTBC.ActivateField ("OptyName");
currentTBC.ClearToQuery();
currentTBC.SetSearchSpec ("OptyName", "*");
currentTBC.ExecuteQuery(ForwardBackward);
isRecord = currentTBC.FirstRecord();
iCounter = 0;
if(isRecord)
{
do
{
indata = currentTBC.GetFieldValue("OptyName");
currentBC.NewRecord(0); //This creates the new record
currentBC.ActivateField("Name");
currentBC.SetFieldValue("Name", indata);
// This is setting the field value for opportunity name
currentBC.WriteRecord(); // writing the record to database.
iCounter++;
} while(currentTBC.NextRecord());
}
}
return (CancelOperation);
}