Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / how to attach the repo...
Finance forum
Suggested answer

how to attach the report controller to runnable class

Posted on by 1,457
I need to run the report using runnable class , for specific test case how can i get this done can anyone plz guide me on this 
 
 
 
 
 
thanks ,
Regards ,
Dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    how to attach the report controller to runnable class
    I'm sorry, but the screenshot doesn't allow anyone to tell why _formDataSource is null. It depends on the code calling getFirstSelection(). The debugger will tell you more.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to attach the report controller to runnable class
      hi ,martin 
    thanks for reply ,
     
    i am getting printMgmtReportFormat.Name fetched correctly,  and the setting code but when debugger goes to  the controller.start operation  i am getting error here ,
  • Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    how to attach the report controller to runnable class
    Please give us more information about the problem. Is it throwing an error? If so, where and what does it say? Or is it actually printed but not to PDF? Or what?
     
    Then tell us what you learned when you debugged your code, before giving up and coming here again. For example, does it go to the 'if' block or the 'else' block? Is printMgmtReportFormat.Name fetched correctly?
     
    Also, if the report uses print management, it's likely that your parameters (such as the file format) are overwritten by values defined by print management.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to attach the report controller to runnable class
    hi ,martin 
    i have made some changes in my code , but still the pdf file is not getting generated , does it need to do any thing with args .
    below is my code .
       public static void main(Args _args)
        {
            BusinessDocumentSubmission              submission;
            BusinessDocumentExecutionActionTmp      executionActionTmp;
            BusinessDocumentActionOutputFileTmp     actionOutputFileTmp;
            Projinvoicejour                         projinvoicejour,projinvoicejourLoc;
            BusinessDocumentSubmissionExternal      submissionExternal;
            BusinessDocumentInfo                    documentInfo;
            ProjType                                projectType;
            PSAProjProposalProj                     projProposalProj;
            PrintMgmtDocInstance	                printMgmtDocInstance;
            PrintMgmtReportFormat	                printMgmtReportFormat;
            PrintMgmtSettings		                printMgmtSetting;
            PrintMgmtReportFormatName	            reportFormatName;
            SRSPrintDestinationSettings             settings;
    
    
    
            select * from submission
                     join  projinvoicejour
                  where projinvoicejour.RecId == submission.REFRECID
                   && projinvoicejour.TableId == submission.REFTABLEID
                   && projinvoicejour.ProjInvoiceId == 'PINV-003773';
    
            select firstonly ProjId from projProposalProj
                exists join projinvoicejourLoc
                where projinvoicejourLoc.ProposalId  == projProposalProj.ProjProposalId
                   && projinvoicejourLoc.RecId   == projinvoicejour.RecId;
    
            projectType = projProposalProj.projTable().Type;
    
            ALSProjInvoicePrintController controller = new ALSProjInvoicePrintController();
      
            if (projectType == ProjType::FixedPrice)
            {
                select printMgmtDocInstance where printMgmtDocInstance.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceFP
                join printMgmtSetting where printMgmtSetting.ParentId == printMgmtDocInstance.RecId
                join printMgmtReportFormat where printMgmtReportFormat.RecId == printMgmtSetting.ReportFormat &&
                    printMgmtReportFormat.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceFP;
                controller.parmReportName(printMgmtReportFormat.Name);
    
                // Change print settings as needed
                settings = controller.parmReportContract().parmPrintSettings();
                settings.printMediumType(SRSPrintMediumType::File);
                settings.fileFormat(SRSReportFileFormat::PDF);
                settings.fileName('UserLicenseCount.pdf');
            }
            else
            {
                select printMgmtDocInstance where printMgmtDocInstance.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceTM
                join printMgmtSetting where printMgmtSetting.ParentId == printMgmtDocInstance.RecId
                join printMgmtReportFormat where printMgmtReportFormat.RecId == printMgmtSetting.ReportFormat &&
                    printMgmtReportFormat.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceTM;
                controller.parmReportName(printMgmtReportFormat.Name);
    
                // Change print settings as needed
                settings = controller.parmReportContract().parmPrintSettings();
                settings.printMediumType(SRSPrintMediumType::File);
                settings.fileFormat(SRSReportFileFormat::PDF);
                settings.fileName('UserLicenseCount.pdf');
            }
     
            controller.parmArgs(_args);
            controller.parmShowDialog(false);
            controller.startOperation();
    }
    
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to attach the report controller to runnable class
    hi martin ,
    Thanks for reply 
      I am using the runnable class to get the report of specific id , so when i run this class the report should get download in the Pdf format and the  str filecontents should get attach to it .
     
    thanks ,
    regards,
    Dinesh
     
  • Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    how to attach the report controller to runnable class
    I can't tell you what to change because I don't know what your code should do and what problem you have with it. You'll have to tell us more.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to attach the report controller to runnable class
    hi , martin 
    i did something like this to add controller to runnable class , can you plz suggest what changes i need to do in code .
    internal final class DTSubmissionXml
    {
        /// <summary>
        /// Class entry point. The system will call this method when a designated menu 
        /// is selected or when execution starts and this class is set as the startup class.
        /// </summary>
        /// <param name = "_args">The specified arguments.</param>
        public static void main(Args _args)
        {
            BusinessDocumentSubmission              submission;
            BusinessDocumentExecutionActionTmp      executionActionTmp;
            BusinessDocumentActionOutputFileTmp     actionOutputFileTmp;
            Projinvoicejour                         projinvoicejour,projinvoicejourLoc;
            BusinessDocumentSubmissionExternal      submissionExternal;
            BusinessDocumentInfo                    documentInfo;
            ProjType                                projectType;
            PSAProjProposalProj                     projProposalProj;
            PrintMgmtDocInstance	                printMgmtDocInstance;
            PrintMgmtReportFormat	                printMgmtReportFormat;
            PrintMgmtSettings		                printMgmtSetting;
            PrintMgmtReportFormatName	            reportFormatName;
    
    
            select * from submission
                     join  projinvoicejour
                  where projinvoicejour.RecId == submission.REFRECID
                   && projinvoicejour.TableId == submission.REFTABLEID
                   && projinvoicejour.ProjInvoiceId == 'PINV-003773';
    
            select firstonly ProjId from projProposalProj
                exists join projinvoicejourLoc
                where projinvoicejourLoc.ProposalId  == projProposalProj.ProjProposalId&&
                    projinvoicejourLoc.RecId   == projinvoicejour.RecId;
    
            projectType = projProposalProj.projTable().Type;
    
            ALSProjInvoicePrintController controller = new ALSProjInvoicePrintController();
      
            if (projectType == ProjType::FixedPrice)
            {
                select printMgmtDocInstance where printMgmtDocInstance.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceFP
                join printMgmtSetting where printMgmtSetting.ParentId == printMgmtDocInstance.RecId
                join printMgmtReportFormat where printMgmtReportFormat.RecId == printMgmtSetting.ReportFormat &&
                    printMgmtReportFormat.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceFP;
                controller.parmReportName(printMgmtReportFormat.Name);
            }
            else
            {
                select printMgmtDocInstance where printMgmtDocInstance.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceTM
                join printMgmtSetting where printMgmtSetting.ParentId == printMgmtDocInstance.RecId
                join printMgmtReportFormat where printMgmtReportFormat.RecId == printMgmtSetting.ReportFormat &&
                    printMgmtReportFormat.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceTM;
                controller.parmReportName(printMgmtReportFormat.Name);
            }
     
            controller.parmArgs(_args);
            controller.parmShowDialog(false);
            controller.startOperation();
    
            submission = BusinessDocumentSubmission::find(submission.RefTableId,submission.RefRecId);
            submissionExternal =  BusinessDocumentSubmissionExternal::find(submission.RefTableId,submission.RefRecId);
    
            if(submission)
            {
                documentInfo = BusinessDocumentServiceController::newSubmission(submission).lookupDocumentInfo();
                if(documentInfo)
                {
                   executionActionTmp  = documentInfo.getExecutionActions();
                    if(executionActionTmp)
                    {
                        if(executionActionTmp.Status == 'Completed' && executionActionTmp.Name == 'Prepare document for submit for Saudi Arabia Zatca service')
                        {
                            actionOutputFileTmp = documentInfo.getOutputFiles();
                            if (actionOutputFileTmp)
                            {
                                guid UID = submission
                                ? submission.UID
                               : submissionExternal.UID;
    
                                if (UID)
                                {
                                    str fileContents = BusinessDocumentServiceController::getOutputFileById(
                                                                       UID,
                                                                       actionOutputFileTmp.ExecutionID,
                                                                       actionOutputFileTmp.ActionID,
                                                                       actionOutputFileTmp.IDName);
                                     
                                }
                            }
                                
                        }
                    
                    }
                  
                }
            }
        }
    
    }
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    how to attach the report controller to runnable class
    Sorry, but it's not clear to me what you need from us. ISLALSProjInvoicePrintControllerExt already is a runnable class.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to attach the report controller to runnable class
    hi ,Martin 
    thanks for reply ,
     
    i am having 2 classes for controller one is controller and one is extension and the report opens by print management . 
    can you plz help me out on this . here is extension which use prinnt management  and below is original controller class .
    class ISLALSProjInvoicePrintControllerExt extends ALSProjInvoicePrintController
    {
        public static void main(Args _args)
        {
            ProjType        projectType;
            projInvoiceJour projInvoiceJour;
            PSAProjProposalProj projProposalProj;
            PrintMgmtDocInstance	printMgmtDocInstance;
            PrintMgmtReportFormat	printMgmtReportFormat;
            PrintMgmtSettings		printMgmtSetting;
            PrintMgmtReportFormatName	reportFormatName;
    
            
            select firstonly ProjId from projProposalProj
                exists join projInvoiceJour
                where projInvoiceJour.ProposalId  == projProposalProj.ProjProposalId&&
                    projInvoiceJour.RecId   == _args.record().RecId;
    
            projectType = projProposalProj.projTable().Type;
    
            ALSProjInvoicePrintController controller = new ALSProjInvoicePrintController();
    		
            if (projectType == ProjType::FixedPrice)
            {
                select printMgmtDocInstance where printMgmtDocInstance.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceFP
                join printMgmtSetting where printMgmtSetting.ParentId == printMgmtDocInstance.RecId
                join printMgmtReportFormat where printMgmtReportFormat.RecId == printMgmtSetting.ReportFormat &&
                    printMgmtReportFormat.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceFP;
                controller.parmReportName(printMgmtReportFormat.Name);
            }
    		else
            {
                select printMgmtDocInstance where printMgmtDocInstance.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceTM
                join printMgmtSetting where printMgmtSetting.ParentId == printMgmtDocInstance.RecId
                join printMgmtReportFormat where printMgmtReportFormat.RecId == printMgmtSetting.ReportFormat &&
                    printMgmtReportFormat.DocumentType == PrintMgmtDocumentType::ISLProjectInvoiceTM;
                controller.parmReportName(printMgmtReportFormat.Name);
            }
    	
            controller.parmArgs(_args);
            controller.parmShowDialog(false);
            controller.startOperation();
        }
    
    }
    /// <summary>
    /// ALSSalesInvoicePrintController
    /// </summary>
    class ALSProjInvoicePrintController extends SrsReportRunController
    {
        ProjInvoiceJour projInvoicejour;
    
        /// <summary>
        /// prePromptModifyContract
        /// </summary>
        protected void prePromptModifyContract()
        {
            Query                   query;
            QueryBuildDataSource    qbds;
            FormDataSource          fds;
    
            query   =   this.getFirstQuery();
            qbds    =   query.dataSourceTable(tableNum(ProjInvoiceJour));
            qbds.clearRanges();
    
            fds = this.parmArgs().record().dataSource();
            for(projInvoicejour = getFirstSelection(fds); projInvoicejour != null; projInvoicejour = fds.getNext())
            {
                qbds.addRange(fieldNum(ProjInvoiceJour, RecId)).value(queryValue(projInvoicejour.RecId));
            }
        }
    
        /// <summary>
        /// main
        /// </summary>
        /// <param name = "_args">_args</param>
        public static void main(Args _args)
        {
            ProjType        projectType;
            projInvoiceJour projInvoiceJour;
            PSAProjProposalProj projProposalProj;
    
            select firstonly ProjId from projProposalProj
                exists join projInvoiceJour
                where projInvoiceJour.ProposalId  == projProposalProj.ProjProposalId&&
                    projInvoiceJour.RecId   == _args.record().RecId;
    
            projectType = projProposalProj.projTable().Type;
    
            ALSProjInvoicePrintController controller = new ALSProjInvoicePrintController();
            if(curExt() == 'ATKW' || curExt() == 'ATOM' || curExt() == 'AAKW')
            {
                if(projectType  == ProjType::FixedPrice)
                {
                    controller.parmReportName(ssrsReportStr(ALSProjInvoicePrint, Report_KD_MileStone));
                }
                else
                {
                    controller.parmReportName(ssrsReportStr(ALSProjInvoicePrint, Report_KD_TM));
                }
               
            }
            else if(curExt() == 'ATAE')
            {
                if(projectType  == ProjType::FixedPrice)
                {
                    controller.parmReportName(ssrsReportStr(ALSProjInvoicePrint, Report_UAE_MileStone));
                }
                else
                {
                    controller.parmReportName(ssrsReportStr(ALSProjInvoicePrint, Report_UAE_TM));
                }
            }
            else
            {
                controller.parmReportName(ssrsReportStr(ALSProjInvoicePrint, Report));
            }
            controller.parmArgs(_args);
            controller.parmShowDialog(false);
            controller.startOperation();
        }
    
    }
     
    thanks ,
     regards 
    Dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    how to attach the report controller to runnable class
    The very first step is deciding which report you want to print.

    By the way, I've noticed a bug in your code: you refer to submissionExternal.UID, but you never populate submissionExternal variable.
     
    It's also not clear to me why you need submissionLoc variable and you don't simply use submission.


Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans