1) Set the datasource property of the MenuItemButton through which the class will be called. Say we have put an action MenuItemButton on CustTrans form.

2) In main method of class use args.record.datasource() to get the datasource object and save it to a FormDataSource variable using a parm method as below

public FormDataSource parmFormDataSource(FormDataSource _formDataSource = formDataSource)
{
formDataSource = _formDataSource;

return formDataSource;
}

public static void main(Args args)
{
RT_MultiSelect runb = new RT_MultiSelect();

runb.parmFormDataSource(args.record().dataSource());

if(runb.prompt())
{
runb.run();
}
}

3) Then loop through the selected records as below

public void run()
{
CustTrans custTrans;

custTrans = formDataSource.getFirst(1);

while (custTrans.RecId != 0)
{
print (custTrans.RecId);

custTrans= formDataSource.getNext();
}
pause;
}

It will print the recids of the records which are selected only.