Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Controller class get multiple records from from

(0) ShareShare
ReportReport
Posted on by 284

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);
    }

}

  • Suggested answer
    Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Controller class get multiple records from from

    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

  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: Controller class get multiple records from from

    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.

    Multi selection with SysOperation framework

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Controller class get multiple records from from

    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.

  • Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Controller class get multiple records from from

    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.

  • Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: Controller class get multiple records from from

    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();
    }

  • Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Controller class get multiple records from from

    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

    www.schweda.net/blog_ax.php

    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.

  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: Controller class get multiple records from from

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,971 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,846 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans