Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

How to print multiple packing slips to file (pdf) simultaneously?

Posted on by 245

Hi,

I would like to print several packing slip documents to file (pdf) simultaneously.

Either from Accounts receivable - periodic - sales update - packing slip and do a select for a number of orders to print packing slip to file or from the print archieve if this would facilitate in any way.

Example:

1. Do a select which returns for example 30 sales orders

2. Post packing slip/print without posting packing slip for these orders

3. Get all packing slips either in one pdf or in 30 different packing slips.

What I would like to avoid is to post all packing slips, print to screen and then go through each packing slip and save it as pdf to disk.

Thanks in advance!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: How to print multiple packing slips to file (pdf) simultaneously?

    Henrik, you can do this with a bit of coding. You need to use CustPackingSlipJour table to select the packing slips you want to print, and then loop through all records and print individual packing slip reports using the SalesFormLetter class (which actually instances SalesFormLetter_PackingSlip class when constructed for packing slips).

    Here's the sample code that creates PDF printouts for all packing slips for a selected date (in this exaple I used the latest date from CustPackingSlipJour table), you can adjust it to your requirements (e.g. change select criteria, use different folder for PDF files, etc.).

    // Created on 11 Jan 2011 by Jovan Bulajic
    static void PrintPackingSlipsToPDF(Args _args)
    {
        CustPackingSlipJour     custPackingSlipJour;
        SalesFormLetter         packingSlip;
        PrintJobSettings        printSet;
        TransDate               filterDate;
        Filename                pdfFile;
        ;

        // Configure printer/PDF settings
        printSet = new printJobSettings();
        printSet.setTarget(PrintMedium::File);
        printSet.format(PrintFormat::PDF);
        printSet.warnIfFileExists(false);
        printSet.suppressScalingMessage(true);
        printSet.setTarget(PrintMedium::File);

        // Initialize the report
        packingSlip = SalesFormletter::construct(DocumentStatus::PackingSlip, false);

        // Select date of the latest packing slip (e.g. today - to use this for testing)
        select maxOf(DeliveryDate) from custPackingSlipJour;
        filterDate = custPackingSlipJour.DeliveryDate;
        info(strFmt('Printing Packing Slips for %1', filterDate));

        // Process all packing slips for the selected date
        while select *
            from custPackingSlipJour
            where custPackingSlipJour.DeliveryDate == filterDate
        {
            // Set the PDF file name
            pdfFile = strFmt('C:\\Temp\\PackingSlip_%1.pdf', custPackingSlipJour.PackingSlipId);
            printSet.fileName(pdfFile);

            // Print packing slip to PDF
            packingSlip.updatePrinterSettingsFormLetter(printSet.packPrintJobSettings());
            custPackingSlipJour.printJournal(packingSlip);
        }
    }

  • Henrik Lenerius Profile Picture
    Henrik Lenerius 245 on at
    Re: How to print multiple packing slips to file (pdf) simultaneously?

    Dear Matt and Steeve,

    I appreciate you taking time to help me out with this.

    However, it seems that I have somewhat not managed to point to my real problem. I do know how to select the sales orders I want, and how to post and print without posting and choosing PDF file as print option.

    The problem is that you will only get one pdf, which just contains just one of the packing slips.

    I am not a developer myself, and I won't be changing any code to solve this problem. But from what I gather from you there is no way to make this work with standard functionality?

    Thanks again!

    //Henrik

  • Steeve Gilbert Profile Picture
    Steeve Gilbert 1,501 on at
    Re: How to print multiple packing slips to file (pdf) simultaneously?

    (1) How to select orders and display the packing slip posting form.  It's easier when you do that on a form that have the SalesTable dataSource with a grid.  Like SalesTable form, but you can also build a custom one.

    SalesTable_ds.query().dataSourceNo(1).addRange(fieldNum(SalesTable, SalesId)).value("SalesId you want to select");
    SalesTable_ds.executeQuery();

    // Select all wanted lines
    salesTabToSelect = SalesTable_ds.getFirst();
    while (salesTabToSelect)
    {
          SalesTable_ds.markRecord(salesTabToSelect, true);
          salesTabToSelect = SalesTable_ds.getNext();
    }

    args.parmEnumType(typeId(DocumentStatus));
    args.parmEnum(DocumentStatus::PackingSlip);
    args.record(SalesTable);

    //Open posting form
    SalesFormLetter::main(args);

    (2) \Classes\SalesEditLinesForm_PackingSlip.  You should be able to control the posting checkbox from here to post or not.  And probably control the "Ok" button to post automatically.

    (3) \Classes\SalesFormLetter_PackingSlip\initPrinterSettingsFormletter.  From there, set the printJobSetting object to default to PDF and specify a filename.

    Problem my arise if multiple packing slip are created, i guess the PDF will be overwritten for every packing slip until the last.  You will probably have to skip the call to "element.reset()" in the report so that only one report (PDF) is generated.

    It's a good challenge you got there. Hope that helps.  If you have other question let us know.

  • Matt Vail Profile Picture
    Matt Vail 30 on at
    Re: How to print multiple packing slips to file (pdf) simultaneously?

    In AR->Periodic->Sales update->Packing slip

    Unchecking "Posting" will prevent the packing slips from actually being posted in AX. Make sure "Print packing slip" is still checked.

    To save to PDF, on the right hand side click on "Printer setup". Choose "File" and in the drop down select "PDF".

    That should give you one PDF with all the Packing Slips you selected.

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,663 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,741 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans