Creating the Business Service
This task is a step in Example of Developing a Task That Assists with Creating Multiple Opportunities.
In this topic, you create the business service that the task UI calls.
To create the business service
-
In the Object Explorer, click Business Service and create a new record with the values shown in the following table.
Property Value Name
MultiTBC_Insert
Project
Multiple Opportunity Task UI
Class
CSSService
Display Name - String Override
MultiTBC_Insert
-
Select the MultiTBC_Insert business service record that you created in the previous step, click the Applet Menu (the cogwheel icon) and then select Edit Server Scripts.
-
In the Scripting Language dialog that opens, select eScript and then click OK.
The script editing window opens with the Service_PreInvokeMethod function selected.
-
Position the cursor in the script editing window and do the following:
-
Right-click, and then select Select All.
-
Right-click, and then select Cut.
-
-
Paste the following script into 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()); } } currentBC = null; currentTBC = null; currentBO = null; return (CancelOperation); }
-
Close the script editing window and then click Yes in the Confirm dialog that opens.
-
In the Object Explorer, expand the Business Service tree and then click Business Service Method.
-
In the Business Service Methods list, create a new business service with the values shown in the following table.
Property Value Name
InsertRecordToTBC
Display Name - String Override
MultiTBCInsertBSM