Business requirement: automatic setting of mail recipient and mail subject during posting
This post describes how to set the mail recipient and mail subject dynamically, but in an automatic way upon posting the packing slip for a purchase order. The printed packing slip is added as PDF to the created mail message. The solution is on an Axapta 3.0 installation, but probably the same can work for other Dynamics AX versions.
Solution
Create a new method in the class PurchFormLetter_PackingSlip.
void initPrintJobSettings()
{
PrintJobSettings printJobSettings;
;
printJobSettings =
new PrintJobSettings(printerSettingsFormletter);
// set the output format of the packing slip to PDF
printJobSettings.preferredMailFormat(PrintFormat::PDF);
// set the mail recipient (this could be parameterised,
// in the example it is hardcoded)
if (purchTable)
printJobSettings.mailTo(“foo@hotmail.com")
// set the mail subject if (purchTable)
printJobSettings.mailSubject(‘@SYS72882’
+ “ “ + purchTable.PurchId);
this.updatePrinterSettingsFormLetter(
printJobSettings.packPrintJobSettings());
}
Add a new method in the class PurchFormLetter.
void initPrintJobSettings()
{
}
Call the method in the main method of the class PurchFormLetter.
{
…
purchFormLetter.parmId(parmId);
purchFormLetter.transDate(systemDateGet());
purchFormLetter.initPrintJobSettings();
if (purchFormLetter.prompt())
{
…
}
Continue reading......