Hello everyone,
I have created a report with contract, controller and DP class. I want to grab all the records selected on the form and loop through them.
Below is my code that grabs 1 record (no matter how many I've selected). What do I need to change to grab all selected records?
class TCI_OutsideServicePackingSlipController extends SrsReportRunController { public static void main(Args _args) { SrsReportRunController controller = new TCI_OutsideServicePackingSlipController(); controller.parmReportName(ssrsReportStr(TCI_OutsideServicePackingSlip, Report)); controller.parmArgs(_args); controller.startOperation(); } protected void prePromptModifyContract() { TCI_OutsideServicePackingSlipContract contract = this.parmReportContract().parmRdpContract(); contract.parmRecId(args.record().RecId); this.parmReportContract().parmReportName(ssrsReportStr(TCI_OutsideServicePackingSlip, Report)); boolean isPreview = false; //Set the target print destination to screen if (isPreview) { this.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Screen); } this.parmshowDialog(!isPreview); this.parmLoadFromSysLastValue(!isPreview); } }
I appreciate everyone's responses and with using pieces of code from all of you, I was able to find the simplest solution to get this working. Hopefully this post can help people in the future.
First add a list in your Contract class
class TCI_OutsideServicePackingSlipContract { List selectedRecs; [ DataMember('selectedRecs'), SysOperationLabelAttribute(literalStr("Recs")), SysOperationHelpTextAttribute(literalStr("Recs")), AifCollectionType('return', Types::String) ] public List parmSelectedRecs(List _selectedRecs = selectedRecs) { selectedRecs = _selectedRecs; return selectedRecs; } }
Next add some code to the Controller to loop through those records. Please note that the datasource table of the form I'm coming from is TCI_OutsideServiceImportLog
class TCI_OutsideServicePackingSlipController extends SrsReportRunController { public static void main(Args _args) { SrsReportRunController controller = new TCI_OutsideServicePackingSlipController(); controller.parmReportName(ssrsReportStr(TCI_OutsideServicePackingSlip, Report)); controller.parmArgs(_args); controller.startOperation(); } protected void prePromptModifyContract() { TCI_OutsideServicePackingSlipContract contract = this.parmReportContract().parmRdpContract(); TCI_OutsideServiceImportLog outsideServiceLog; MultiSelectionHelper selection; List selectedRecsFromController = new List(Types::Int64); if (this.parmArgs().dataset() == tableNum(TCI_OutsideServiceImportLog)) { selection = MultiSelectionHelper::createFromCaller(this.parmArgs().caller()); outsideServiceLog = selection.getFirst(); while (outsideServiceLog) { selectedRecsFromController.addEnd(outsideServiceLog.RecId); outsideServiceLog = selection.getNext(); } } contract.parmSelectedRecs(selectedRecsFromController); this.parmReportContract().parmReportName(ssrsReportStr(TCI_OutsideServicePackingSlip, Report)); boolean isPreview = false; //Set the target print destination to screen if (isPreview) { this.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Screen); } this.parmshowDialog(!isPreview); this.parmLoadFromSysLastValue(!isPreview); } }
Lastly, when you want to loop through the records in that list, you can do it this way. You won't have to do the _recordBuilder code unless you are doing a Docentric report like I am doing.
TCI_OutsideServicePackingSlipContract reportContract = this.getSrsRdpContract(); TCI_OutsideServiceImportLog outsideServiceImportLog; InventTable inventTable; List selectedRecsDSP; ListEnumerator enumerator; selectedRecsDSP = reportContract.parmSelectedRecs(); enumerator = selectedRecsDSP.getEnumerator(); enumerator.reset(); while(enumerator.moveNext()) { select outsideServiceImportLog where outsideServiceImportLog.RecId == enumerator.current() join inventTable where inventTable.ItemId == outsideServiceImportLog.ItemId; if (outsideServiceImportLog) { _recordBuilder.addRecordWithAllFields(outsideServiceImportLog); _recordBuilder.addRecordWithAllFields(inventTable); _recordBuilder.goToTopRecord(); } }
And that's it! Hopefully someone finds this helpful
Hi Andrew,
I think this will help you solve your issue. I created this post, see link below. I have to sort out the horrible formatting in the blog but if you copy the code it should be okay.
Hi Andrew,
Call the datasource method from the table buffer - Form that use Multiselectionhelper class or use normal for loop to get the selected record in the form.
For passing the selected record to the dp class you need to create a list parameter.
Once looping through the records using MultiselectionHelper class insert all the records into the list and pass the list to dp class using PrePrompModifiyContract method.
Refer to the below link.
http://axhelper.blogspot.com/2012/01/pass-data-source-records-to-class-or.html
Thanks,
Girish S.
But I can't seem to put this code into a controller class. My button is pointed to a controller to print a SSRS report and I need to put the records into a container of some sort and it's not working. So if you know a controller class that does this, then I can look at that.
This is how to loop through the selected records in a form. You will have to change it for your needs.
//loop through selected records MultiSelectionHelper helper = MultiSelectionHelper::construct(); helper.parmDataSource(_args.record().dataSource()); Common buffer = helper.getFirst(); while (buffer) { //do stuff buffer = helper.getNext(); }
Hi Anton,
If you could point me in the right direction of examples where this is used in a Controller class to get the records to the DataProvider Class, that would be great. I've been researching for the past bunch of hours and can't find much. I found this link
But when I tried it, I got an error saying can't return type Container
So I'm not sure where to go from here as I have never done this. If you know an existing controller class that does this that I can look at, please let me know.
For looping through the selected records on a form, use the MultiSelectionHelper class. There are examples in the standard application on how to use it.
André Arnaud de Cal...
291,971
Super User 2025 Season 1
Martin Dráb
230,846
Most Valuable Professional
nmaenpaa
101,156