Hybrid action execution in IViews

Quick Guide >>

Hybrid action execution is used when task execution in an action needs to be split up into various stages – i.e  a few tasks in an action needs to be executed in the beginning, followed by some for all or selected rows and finally some more tasks at the end.

Such actions  can be defined in IViews as given below :

Set the event to “All Selected rows”.

The action should contain only one script. The format of the script should be as below

@start

//these statements will be executed at the start of the action and not for every row.

@row

//these statements will be executed for every selected row

@end

//these statements will be executed after all rows are completed.

Scenario : Copy selected rows from an IView to a grid in a Tstruct

Consider a requirement where on click of a button in an IView, the selected rows have to be stored to a table and then a TStruct has to be opened that fills a grid from these selected rows.

Assume that the following structures exist – Employee Master TStruct, Employee List Iview and Bonus Tstruct.

  • Employee Master consists of the fields Empid, Empname, Address and Net Pay.
  • Employee List IView lists these employees.
  • Bonus Tstruct has the following fields in dc1 – Bonus Id, Bonus date and a grid DC with Empid, EmpName, NetPay,BonusAmt,FinalAmt.  Set suitable properties for Bonus Id and Bonus date.

We require that the selected employees from the Employee List IView  should be populated into the grid with in Bonus TStruct .

Follow the steps below to implement hybrid action that would be copy the selected rows from Employee List IView to Bonus TStruct.

  • Create a temporary table bonustemp in the backend with the fields that need to be transferred from the IView to TStruct. In our example bonustemp consists of fields Empid,Empname ,NetPay,Ipadd.
  • In the Employee List IView, create an action named Bonus with the following script

@START

firesql({sql1},{ delete from bonustemp where ipadd= (select sys_context(‘userenv’,’ip_address’)  ip_address  from dual ) })

@ROW

firesql({sql2},{delete from  bonustemp where empid = :empid})

firesql({sql2},{insert into bonustemp(empmastid,empid,empname, netpay,ipadd) values(:empmastid,:empid,:empname,:netpay,sys_context(‘userenv’,’ip_address’) ) })

@END

Note : The ipadd field is to store the IP address of the user who has selected the records. This is useful in a scenario where multiple users are using the application.

  • Add the command OpenTStruct in the same action and select Bonus as the TStruct to be opened. Click Apply.
  • Under Events, select All selected Rows and save the action.
  •  In the Bonus Tstruct, add a FillGrid in the header with the following properties:

 

Type Properties
FillGrid Caption = From EmpSQL = select empid,empname,netpay from bonustemp where ipadd = sys_context(‘userenv’,’ip_address’)

TargetDC = DC2

MapDetails = map the corresponding fields here

MultiSelect = False

 

 

  • Add a button Fill in the Employee list IView and link the action Bonus to it.

After saving the changes,run the Employee list IView and select some records. Run the action by clicking on Fill button – this will open the Bonus TStruct. Click on the grid to see the selected records being populated.