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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

how to attach the report controller to runnable class

(0) ShareShare
ReportReport
Posted on by 1,836
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
  • Suggested answer
    Martin Dráb Profile Picture
    241,315 Most Valuable Professional on at
    Here is an example; adjust it as needed:
    SrsReportRunController          controller = new SrsReportRunController();
    SysUserLicenseCountRDPContract  rdpContract = new SysUserLicenseCountRDPContract();
    SRSPrintDestinationSettings     settings;
     
    // Define report and report design to use
    controller.parmReportName(ssrsReportStr(SysUserLicenseCountReport, Report));
    // Use execution mode appropriate to your situation
    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    // Suppress report dialog
    controller.parmShowDialog(false);
     
    // Explicitly provide all required parameters
    rdpContract.parmReportStateDate(systemDateGet());
    controller.parmReportContract().parmRdpContract(rdpContract);
     
    // Change print settings as needed
    settings = controller.parmReportContract().parmPrintSettings();
    settings.printMediumType(SRSPrintMediumType::File);
    settings.fileFormat(SRSReportFileFormat::Excel);
    settings.fileName('UserLicenseCount.xlsx');
     
    // Execute the report
    controller.startOperation();
  • Dineshkarlekar Profile Picture
    1,836 on at
    Below is the code for my runnable class 
    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,submissionLoc;
            BusinessDocumentExecutionActionTmp      executionActionTmp;
            BusinessDocumentActionOutputFileTmp     actionOutputFileTmp;
            Projinvoicejour                         projinvoicejour;
            BusinessDocumentSubmissionExternal      submissionExternal;
            BusinessDocumentInfo                    documentInfo;
    
    
            select * from submission
                     join  projinvoicejour
                  where projinvoicejour.RecId == submission.REFRECID
                   && projinvoicejour.TableId == submission.REFTABLEID
                   && projinvoicejour.ProjInvoiceId == 'PINV-003773';
    
            submissionLoc = BusinessDocumentSubmission::find(submission.RefTableId,submission.RefRecId);
    
            if(submissionLoc)
            {
                documentInfo = BusinessDocumentServiceController::newSubmission(submissionLoc).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);
                                     
                                }
                            }
                                
                        }
                    
                    }
                  
                }
            }
        }
    
    }
    here is my code where i want generate the ssrs report for the "PINV-003773" invoice id , how can i get this done , plz help me out on this . 
     
    thanks ,
    Regards,
    Dinesh 
  • Martin Dráb Profile Picture
    241,315 Most Valuable Professional on at
    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.


  • Dineshkarlekar Profile Picture
    1,836 on at
    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
    241,315 Most Valuable Professional on at
    Sorry, but it's not clear to me what you need from us. ISLALSProjInvoicePrintControllerExt already is a runnable class.
  • Dineshkarlekar Profile Picture
    1,836 on at
    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
    241,315 Most Valuable Professional on at
    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
    1,836 on at
    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
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    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();
    }
    
     
  • Martin Dráb Profile Picture
    241,315 Most Valuable Professional on at
    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 507 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 419 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 155

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans