Dynamics AX Blog - Posts from November 2014
Post sales order confirmation through codeWith the help of the following lines, I want to show how you can post a sales order confirmation by code.
static void postSalesConfirmation(Args _args)
{
SalesTable salesTable = SalesTable::find("000747");
SalesFormLetter salesFormLetter;
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All);
} |
Post sales packing slip through codeWith the help of the following lines, I want to show how you can post a sales packing slip by code.
static void postSalesPackingslip(Args _args)
{
SalesTable salesTable = SalesTable::find("000747");
SalesFormLetter salesFormLetter;
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All);
} |
Post sales invoice through codeWith the help of the following lines, I want to show how you can post a sales invoice by code.
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 codeThe 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 codeThe 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.
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 codeThe 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()); salesConfirmJournalPrint.printJournal(set); } |
|
|
|
|
|
|

With the help of the following lines, I want to show how you can post a purchase order by code.
Those, who want to have more control over the data to be posted, should take a look at the parameters of purchFormLetter.update().
static void postPurchaseOrder(Args _args) { PurchTable purchTable = PurchTable::find("000025"); PurchFormLetter purchFormLetter; purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder); purchFormLetter.update(purchTable, "", systemDateGet(), PurchUpdate::All); }