Wednesday, December 17, 2008

How to use X++ to change the printer settings of SO's and PO's

If you are developing solutions with some automated procedures on sales orders or purchase orders, you might want to control how documents are being printed from the orders. These examples show you how to control this with X++ code.

The SalesFormLetter and PurchFormLetter classes has methods that gives you an easy interface to change the printer settings for a sales order or a purchase order document.

The following example shows you how to open the printer settings dialog and let the user change these for later use:
static void CallFormLetterPrinterSettings(args a)
{
     SalesFormLetter salesFormLetter;
     ;
     salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);      salesFormLetter.getLast();  
 
 SalesFormLetter::callPrinterSettingsFormletter(salesFormLetter);       
 salesFormLetter.saveLast();
}
This next example shows you how to change the printer settings without the user dialog:
static void ChangeFormLetterPrinterSettings(args a)
{
     SalesFormLetter  salesFormLetter;
     PrintJobSettings  printJobSettings;
     ;
   
 salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);      salesFormLetter.getLast();   
 
 // Create new instance of PrintJobSettings, with the settings from the SalesFormLetter      printJobSettings = new PrintJobSettings(salesFormLetter.printerSettingsFormletter());   
 

 // Change the number of copies to 17
 // (Remember to change it back! The world is already  loosing rainforest at a much to fast  pace)
     printJobSettings.copies(17);   

 // Pack and update the settings on the SalesFormLetter      salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());  salesFormLetter.saveLast();
}

static void ChangeFormLetterPrinterSettings(args a)
{
     SalesFormLetter  salesFormLetter;
     PrintJobSettings  printJobSettings;
     ;
   
 salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);      salesFormLetter.getLast();   
 
 // Create new instance of PrintJobSettings, with the settings from the SalesFormLetter      printJobSettings = new PrintJobSettings(salesFormLetter.printerSettingsFormletter());   
 
 // Change the number of copies to 17
 // (Remember to change it back! The world is already  loosing rainforest at a much to fast  pace)
     printJobSettings.copies(17);   

 // Pack and update the settings on the SalesFormLetter      salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());  salesFormLetter.saveLast();
}

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...