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, ...
Answered

Print Management: I Have 2 Custom Invoice Reports Designs, But Only The Last One Added is Printing

(0) ShareShare
ReportReport
Posted on by 1,036

Hello awesome community!

I'm new to print management.

I created 2 custom designs for FreeTextInvoice. I want the user to choose the design he prefers, so he should be able to choose between these 2 custom designs.

What I did after creating the report with 2 different designs is that I have created a class and put in it the following event handler method:

[SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void getDefaultReportFormatDelegateHandler(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::SalesFreeTextInvoice:
                _result.result(ssrsReportStr(FreeTextInvoiceCustom, MyCustomDesign1);
                _result.result(ssrsReportStr(FreeTextInvoiceCustom, MyCustomDesign2);
                break;
        }
    }

Both of my custom designs appeared in the print management for Free Text Invoice in the AR > Set-up > Form Setup > print management.

But my issue is that when I print the Free Text Invoice, it will always print MyCustomDesign2, the last one added in the switch case in the method above.

Even though I choose MyCustomDesign1 or I choose the original standard FreeTextInvoice.Report design in Form Set-up > Print management, it will always print MyCustomDesign2.

And also, even though while generating the report, it says that it is generating the report design name I am selecting in the print management, but when it finishes generating and shows the invoice, it always shows MyCustomDesign2.

Unless I remove the line for the MyCustomDesign2 in the method above, it will always be the one to print.

What am I missing or doing wrong?

I want the user to be able to choose the invoice design he prefers and be able to switch back.

Any advice is appreciated!

Thanks in advance!

I have the same question (0)
  • Verified answer
    YY Lim Profile Picture
    960 on at

    This is because your code will always return the design2.

    You need code before the switch case get the right reportDesign first. If no reportDesign use the design1

    Add line before your code to call static method:

    PrintMgmtReportFormatName reportName = YourClassName::getPrintMgmtReport(_docType);

    switch (_docType)

           {

               case PrintMgmtDocumentType::SalesFreeTextInvoice:

                    if (!reportName)
                    {
                        reportName = ssrsReportStr(FreeTextInvoiceCustom, MyCustomDesign1);
                    }

                   break;

           }

    A static method:

    public static PrintMgmtReportFormatName getPrintMgmtReport(PrintMgmtDocumentType _printMgmtDocumentType)

       {

           PrintMgmtReportFormatName   reportFormatName;

           PrintMgmtSettings           printMgmtSettings;

           PrintMgmtReportFormat       printMgmtReportFormat;

           PrintMgmtDocInstance        printMgmtDocInstance;

           select DocumentType, RecId from printMgmtDocInstance

               where printMgmtDocInstance.DocumentType == _printMgmtDocumentType

           join  ParentId, ReportFormat from printMgmtSettings

               where printMgmtSettings.ParentId == printMgmtDocInstance.RecId

           join RecId, DocumentType, Name from printMgmtReportFormat

               where   printMgmtReportFormat.RecId == printMgmtSettings.ReportFormat &&

               printMgmtReportFormat.DocumentType == _printMgmtDocumentType;

           reportFormatName = printMgmtReportFormat.Name;

           return reportFormatName;

       }

  • Momochi Profile Picture
    1,036 on at

    Hi dear Yuan!,

    Thank you your code actually worked. So I have to check the report name first before calling the result method.

    But I also now having a new issue, where is If there was a new design created (Design3), it will not be listed in the print management, because the result method will not be called unless the reportName==ssrsReportStr(FreeTextInvoiceCustom, Design3).

    Now my code looks like this after implementing your code:

    [SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
        public static void getDefaultReportFormatDelegateHandler(PrintMgmtDocumentType _docType, EventHandlerResult _result)
        {
            PrintMgmtReportFormatName reportName = YourClassName::getPrintMgmtReport(_docType);
    
    
            switch (_docType)
            {
    
                case PrintMgmtDocumentType::SalesFreeTextInvoice:
                    if(reportName == ssrsReportStr(FreeTextInvoiceCustom, Design1))
                        _result.result(ssrsReportStr(FreeTextInvoiceCustom, Design1));
                    else if(reportName == ssrsReportStr(FreeTextInvoiceCustom, Design2))
                        _result.result(ssrsReportStr(FreeTextInvoiceCustom, Design2));
    				else if(reportName == ssrsReportStr(FreeTextInvoiceCustom, Design3))
    					_result.result(ssrsReportStr(FreeTextInvoiceCustom, Design3));
                    break;
    		}
    	}

    The newly added design3 is not listed in the print management. So I am unable to choose this design.

    I thought of calling the result methods for all designs before the if statement, so they can be added first before choosing which one based on the reportName chosen. But using this approach I will not be able to go back and choose the original standard design (FreeTextInvoice.Report).

    What else I am missing?

    Thanks a lot!

  • Verified answer
    YY Lim Profile Picture
    960 on at

    You need to extend another class to add. The previous class remain the same, you don't need the if and else.

    [ExtensionOf(classStr(PrintMgmtReportFormatPopulator))]

    final class ABCPrintMgmtReportFormatPopulator_Extension

    {

        public void populate(boolean _deleteAll, boolean _showConfirmation)

       {

           next populate(_deleteAll, _showConfirmation);

           this.addOther(PrintMgmtDocumentType::SalesFreeTextInvoice,

                           ssrsReportStr(FreeTextInvoiceCustom, Design1),

                           ssrsReportStr(FreeTextInvoiceCustom, Design2),

                           ssrsReportStr(FreeTextInvoiceCustom, Design3),

                           #NoCountryRegionId);

       }

    }

  • Momochi Profile Picture
    1,036 on at

    Thank you so much dear Yuan!!

    Yeah regarding my IF statement I don't what was I smoking that night public static void getDefaultReportFormatDelegateHandler(PrintMgmtDocumentType _docType, EventHandlerResult _result) { PrintMgmtReportFormatName reportName = YourClassName::getPrintMgmtReport(_docType); switch (_docType) { case PrintMgmtDocumentType::SalesFreeTextInvoice: _result.result(reportName); break; case PrintMgmtDocumentType::SalesOrderInvoice: _result.result(reportName); break; case PrintMgmtDocumentType::PurchaseOrderInvoice: _result.result(reportName); break; } }

    The Extension Class Code:

    [ExtensionOf(classStr(PrintMgmtReportFormatPopulator))]
    public final class MyCustom_PrintMgmtReportFormatPopulator_Extension
    {
        #ISOCountryRegionCodes
        #PrintMgmtSetup
        #RusReportFormats
        public void populate(boolean _deleteAll, boolean _showConfirmation)
    
        {
    
            next populate(_deleteAll, _showConfirmation);
    
            this.addOther(PrintMgmtDocumentType::SalesFreeTextInvoice,
    
                           ssrsReportStr(FreeTextInvoiceCustom, Design1),
    
                           ssrsReportStr(FreeTextInvoiceCustom, Design1),
    
                           #NoCountryRegionId);
    
            this.addOther(PrintMgmtDocumentType::SalesFreeTextInvoice,
    
                           ssrsReportStr(FreeTextInvoiceCustom, Design2),
    
                           ssrsReportStr(FreeTextInvoiceCustom, Design2),
    
                           #NoCountryRegionId);
    
            this.addOther(PrintMgmtDocumentType::SalesFreeTextInvoice,
    
                           ssrsReportStr(FreeTextInvoiceCustom, Design3),
    
                           ssrsReportStr(FreeTextInvoiceCustom, Design3),
    
                           #NoCountryRegionId);
    					   
    	}
    }

    Thanks again :D

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 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans