web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Controller class get multiple records from from

(0) ShareShare
ReportReport
Posted on by 313

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 have the same question (0)
  • Suggested answer
    Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

    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.

  • Andrew Huisman Profile Picture
    313 on at

    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.

  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

    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
    313 on at

    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.

  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    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.

  • Suggested answer
    Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

    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
    Andrew Huisman Profile Picture
    313 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans