Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Controller class run code after prompt but before report is printed

(0) ShareShare
ReportReport
Posted on by 284

Hello everyone,

I'm posting a new thread for a new question that came from this post
Pass parameter from form to report - Dynamics 365 Finance Forum Community Forum

Right now I'm running a SSRS report and need to create a record of that report being run.  The problem is the way I have it at the moment, it creates the records before it's even prompted where you want to print the report.  So if you click cancel, the records are already in the table.

I would like to be able to create the records after the prompt, but before it attempts to print the report.

I put the line of code that creates the record AFTER startOperation() but that runs after the DSP class has been called (DSP class is Docentric class)

Does anyone have a suggestion how I should do what I need?

Here is my controller class now.  You can see I commented out the createReportData(), made a new method that just grabs the next packingSlipId so we can put it in the contract, and then attempted to put createReportData after startOperation() but this isn't working right

class TCI_OutsideServicePackingSlipController extends SrsReportRunController
{
    TCI_OutsideServicePackingSlipHeader packingSlipHeader;
    TCI_OutsideServicePackingSlipId     packingSlipId;
    public static void main(Args _args)
    {
        TCI_OutsideServicePackingSlipController     controller = new TCI_OutsideServicePackingSlipController();
        
        controller.parmReportName(ssrsReportStr(TCI_OutsideServicePackingSlip, Report));
        controller.parmArgs(_args);
        //controller.createReportData();
        controller.getPackingSlipId();
        controller.startOperation();
        controller.createReportData();
    }

    private void getPackingSlipId()
    {
        packingSlipId = NumberSeq::newGetNum(ProdParameters::numRefTCI_OutsideServicePackingSlipEDT()).num();
    }

    private void createReportData()
    {
        if (!args.caller())
        {
            throw error("This report is implemented in such a way that it must be called from a form.");
        }
 
        MultiSelectionHelper helper = MultiSelectionHelper::createFromCaller(args.caller());
 
        TCI_OutsideServiceImportLog outsideServiceImport = helper.getFirst();

        ttsBegin;
 
        //packingSlipHeader.TCI_OutsideServicePackingSlipId   = NumberSeq::newGetNum(ProdParameters::numRefTCI_OutsideServicePackingSlipEDT()).num();
        packingSlipHeader.TCI_OutsideServicePackingSlipId   = packingSlipId;
        packingSlipHeader.PurchId                           = outsideServiceImport.ResultNumber;
        packingSlipHeader.VendAccount                       = outsideServiceImport.VendAccount;
        packingSlipHeader.TCI_ScanRefNumber                 = outsideServiceImport.TCI_ScanRefNumber;
        packingSlipHeader.insert();
 
        int sequence;

        while (outsideServiceImport.RecId != 0)
        {
            TCI_OutsideServicePackingSlipDetails packingSlipDetails;
 
            packingSlipDetails.TCI_OutsideServicePackingSlipId  = packingSlipHeader.TCI_OutsideServicePackingSlipId;
            packingSlipDetails.Seq                              = sequence;
            packingSlipDetails.ItemId                           = outsideServiceImport.ItemId;
            packingSlipDetails.QtyOrdered                       = outsideServiceImport.Qty;
            packingSlipDetails.insert();
  
            sequence  ;
  
            outsideServiceImport = helper.getNext();
        }
 
        ttsCommit;
    }

    protected void prePromptModifyContract()
    {
        super();

        TCI_OutsideServicePackingSlipContract   contract = this.parmReportContract().parmRdpContract();
        
        contract.parmPackingSlipId(packingSlipId);

    }

}

  • Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: Controller class run code after prompt but before report is printed

    You are welcome!

  • Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Controller class run code after prompt but before report is printed

    That was it!  Thank you so much!

  • Verified answer
    Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: Controller class run code after prompt but before report is printed

    Hi,

    Looking at the SrsReportRunController class, I see a run method. That method will only be called if the report should be rendered/created.

    You could create your data before the run is executed by overriding the run method in your class and calling your createReportData method before calling super().

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,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans