Dynamics AX Blog - Microsoft Dynamics AX (Axapta) - Page 15

These posts are machine-translated.
Currently, only posts from category »Microsoft Dynamics AX (Axapta)« are displayed Filter entfernen

In recent years, i spent a lot of time in developing in the environment of Microsoft Dynamics AX (formerly Axapta). During this time i created a lot of code, from which I could imagine, that it might be very useful for other AX developers too. But I will present also tips and tricks round the powerful ERP system.

Subscribe to RSS feed of this category

Post sales invoice through code

With the help of the following lines, I want to show how you can post a sales invoice by code.

Those, who want to have more control over the data to be posted, should take a look at the parameters of salesFormLetter.update().

static void postSalesInvoice(Args _args)
{
    SalesTable salesTable = SalesTable::find("000747");
    SalesFormLetter salesFormLetter;

    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
    salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All);
}

 
 

Print packing slip through code

The following job demonstrates, how you can print an existing Sales packing slip through code. The example sends the report to screen.

static void printSalesPackingSlipThroughCode(Args _args)
{
    SalesPackingSlipJournalPrint salesPackingSlipJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(CustPackingSlipJour::findRecId(5637161120));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen);

    // Initalize
    salesPackingSlipJournalPrint = SalesPackingSlipJournalPrint::construct();
    salesPackingSlipJournalPrint.parmPrintFormletter(NoYes::Yes);
    salesPackingSlipJournalPrint.parmUsePrintManagement(false);
    salesPackingSlipJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    salesPackingSlipJournalPrint.printJournal(set);
}

Changing the parameter of the instance of SRSPrintDestinationSettings allows you to send the sales packing slip to printer, file or mail. The next example creates a PDF-file.

static void printSalesPackingSlipThroughCode(Args _args)
{
    SalesPackingSlipJournalPrint salesPackingSlipJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(CustPackingSlipJour::findRecId(5637161120));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF);
    srsPrintDestinationSettings.fileName(@'c:	emppackingslip.pdf');
    srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::File);
    srsPrintDestinationSettings.numberOfCopies(1);
    srsPrintDestinationSettings.overwriteFile(true);

    // Initalize
    salesPackingSlipJournalPrint = SalesPackingSlipJournalPrint::construct();
    salesPackingSlipJournalPrint.parmPrintFormletter(NoYes::Yes);
    salesPackingSlipJournalPrint.parmUsePrintManagement(false);
    salesPackingSlipJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    salesPackingSlipJournalPrint.printJournal(set);
}

If you want to print multiple sales confirmations at once, you have to add the corresponding CustPackingSlipJour-records to the set called "set:

    ...    
    // Add record
    set.add(CustPackingSlipJour::findRecId(5637155842));
    set.add(CustPackingSlipJour::findRecId(5637145354));
    ...

To additionally save the sales packing slip to print archive, you can add the following line:

    ...    
    srsPrintDestinationSettings.parmPrintToArchive(true);
    ...

 
 

Create primary address through code

The following lines show an example of how you can create a (primary) address for an existing party in the global address book by x ++ code.

The address will only be marked as primary, if no other primary address exists for this party!

static void createPartyAddress(Args _args)
{
    DirPartyTable dirPartyTable = DirPartyTable::findByNum("???100000");
    DirParty dirParty;
    DirPartyPostalAddressView dirPartyPostalAddressView;

    // Create instance of dirParty
    dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), dirPartyTable.partyType());

    // Create primary address
    dirPartyPostalAddressView.LocationName      = "Office";
    dirPartyPostalAddressView.City              = "Vienna";
    dirPartyPostalAddressView.Street            = "Kärtnerring";
    dirPartyPostalAddressView.StreetNumber      = "18";
    dirPartyPostalAddressView.CountryRegionId   = "AUT";
    dirPartyPostalAddressView.IsPrimary         = NoYes::Yes;

    dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
}

 
 

Print sales confirmation through code

The following job demonstrates, how you can print an existing Sales confirmation through code. The example sends the report to screen.

static void printSalesConfirmThroughCode(Args _args)
{
    SalesConfirmJournalPrint salesConfirmJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(CustConfirmJour::findRecId(5637155842));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen);

    // Initalize
    salesConfirmJournalPrint = SalesConfirmJournalPrint::construct();
    salesConfirmJournalPrint.parmPrintFormletter(NoYes::Yes);
    salesConfirmJournalPrint.parmUsePrintManagement(false);
    salesConfirmJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    salesConfirmJournalPrint.printJournal(set);
}

 
 

Print purchase order through code

The following job demonstrates, how you can print an existing Purchase order through code. The example sends the report to screen.

static void printPurchaseOrderThroughCode(Args _args)
{
    PurchPurchOrderJournalPrint purchPurchOrderJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(VendPurchOrderJour::findRecId(5637179849));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen);

    // Initalize
    purchPurchOrderJournalPrint = PurchPurchOrderJournalPrint::construct();
    purchPurchOrderJournalPrint.parmPrintFormletter(NoYes::Yes);
    purchPurchOrderJournalPrint.parmUsePrintManagement(false);
    purchPurchOrderJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    purchPurchOrderJournalPrint.printJournal(set);
}

 
 

Print sales invoice through code

The following job demonstrates, how you can print an existing Sales invoice through code. The example sends the report to screen.

static void printSalesInvoiceThroughCode(Args _args)
{
    SalesInvoiceJournalPrint salesInvoiceJournalPrint;
    Set set = new Set(Types::Record);
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    // Add record
    set.add(CustInvoiceJour::findRecId(5637188088));

    // Set printer settings
    srsPrintDestinationSettings = new SRSPrintDestinationSettings();
    srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen);

    // Initalize
    salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct();
    salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes);
    salesInvoiceJournalPrint.parmUsePrintManagement(false);
    salesInvoiceJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());

    // Print
    salesInvoiceJournalPrint.printJournal(set);
}

 
 

Query On-Hand inventory using specific inventory-dimensions

Using the class InventDimOnhand, you can determine the on-hand inventory of articles and/or specific inventory-dimensions.

The following job determines the inventory for a specific item and a specific inventlocation. This is grouped per color.

static void getInventOnhandExample(Args _args)
{
    ItemId itemId;
    InventDimOnHand inventDimOnHand;
    InventDimParm inventDimParmOnHandLevel;
    InventDimOnHandIterator inventDimOnHandIterator;
    InventDimOnHandMember inventDimOnHandMember;
    InventDim inventDim;
    InventDim inventDimCriteria;
    InventDimParm inventDimParmCriteria;

    // Item: Query specific item
    itemId = "DMO003";
    
    // inventDimCriteria: Apply ranges
    inventDimCriteria.wmsLocationId             = "12-1";
    inventDimCriteria.InventBatchId             = "DMOBatch001";

    // inventDimParmCriteria: should values from inventDimCriteria be used?
    inventDimParmCriteria.ItemIdFlag            = false;
    inventDimParmCriteria.InventSiteIdFlag      = false;
    inventDimParmCriteria.InventLocationIdFlag  = false;
    inventDimParmCriteria.wmsLocationIdFlag     = true;     // wmsLocationId from inventDimCriteria will be used
    inventDimParmCriteria.wmsPalletIdFlag       = false;
    inventDimParmCriteria.InventBatchIdFlag     = false;    // inventBatchId from inventDimCriteria will not be used
    inventDimParmCriteria.InventSerialIdFlag    = false;
    inventDimParmCriteria.ConfigIdFlag          = false;
    inventDimParmCriteria.InventSizeIdFlag      = false;
    inventDimParmCriteria.InventColorIdFlag     = false;
    inventDimParmCriteria.InventStyleIdFlag     = false;

    // inventDimParmOnHandLevel: Which dimensions should be used to group for?
    // inventDimParmOnHandLevel necessary for inventDimOnHandLevel::DimParm
    inventDimParmOnHandLevel.ItemIdFlag            = true;      // necessary
    inventDimParmOnHandLevel.InventSiteIdFlag      = false;
    inventDimParmOnHandLevel.InventLocationIdFlag  = false;
    inventDimParmOnHandLevel.wmsLocationIdFlag     = false;
    inventDimParmOnHandLevel.wmsPalletIdFlag       = false;
    inventDimParmOnHandLevel.InventBatchIdFlag     = false;
    inventDimParmOnHandLevel.InventSerialIdFlag    = false;
    inventDimParmOnHandLevel.ConfigIdFlag          = false;
    inventDimParmOnHandLevel.InventSizeIdFlag      = false;
    inventDimParmOnHandLevel.InventColorIdFlag     = true;      // group by color
    inventDimParmOnHandLevel.InventStyleIdFlag     = false;

    inventDimOnHand = InventDimOnHand::newAvailPhysical(itemId,
                                                        inventDimCriteria,
                                                        inventDimParmCriteria,
                                                        InventDimOnHandLevel::DimParm,
                                                        inventDimParmOnHandLevel);

    inventDimOnHandIterator = inventDimOnHand.onHandIterator();
    while (inventDimOnHandIterator.more())
    {
        inventDimOnHandMember = inventDimOnHandIterator.value();

        inventDim = InventDim::find(inventDimOnHandMember.parmInventDimId());

        info(con2Str([  inventDimOnHandMember.parmItemId(),
                        inventDim.InventSiteId,
                        inventDim.InventLocationId,
                        inventDim.wmsLocationId,
                        inventDim.wmsPalletId,
                        inventDim.InventBatchId,
                        inventDim.InventSerialId,
                        inventDim.ConfigId,
                        inventDim.InventSizeId,
                        inventDim.InventColorId,
                        inventDim.InventStyleId,
                        inventDimOnHandMember.parmInventQty()]));

        inventDimOnHandIterator.next();
    }
}

The output of the above job looks is an infolog like the following:

DMO003,,,12-1,,,,,,Cherry,,54
DMO003,,,12-1,,,,,,Black,,100


 
 
Pages « 1 ... 12 13 14 15 16 17 18 ... 23 » 

 

 
 
 
Posts of the actual month
Mai 2025
MoTuWeThFrSaSu
 1234
567891011
12131415161718
19202122232425
262728293031 
 
© 2006-2025 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.