How to allign text vertically on report

Let’s assume you have a report in Ax ,based on table Company Info.Your report is showing some company  information like company name,company address.
I have  put all the code together in a display method

Display container showCompanyvertical()
{
System.Drawing.Bitmap   BarcodeBitmap;
System.Drawing.Graphics BarcodeGraphics;
int     dx=200;
int     dy=200;
str     barcodetxt;
Image   BarcodeImage;
System.Drawing.Pen                TxtPen;
System.Drawing.Brush              TxtBrush;
System.Drawing.Brush              DrawBrush;
System.Drawing.StringFormat       StringFormat;
System.Drawing.StringAlignment    StringAlignment;
System.Drawing.Font BarcodeFont = new System.Drawing.Font(‘Times New Roman’,12,System.Drawing.FontStyle::Regular);
Int64             BarcodeBitmapPtr;
BarcodeCode128    MyBarcode = BarcodeCode128::construct();
;
BarcodeImage = new Image();
BarcodeBitmap = new System.Drawing.Bitmap(dx,dy);
BarcodeGraphics = System.Drawing.Graphics::FromImage(BarcodeBitmap);
barcodetxt =this.companyName()+”\n”+ this.companyAddress();
// clear canvas
DrawBrush = System.Drawing.Brushes::get_White();
BarcodeGraphics.FillRectangle(DrawBrush,0,0,any2int(dx),any2int(dy));

// set barcode text
TxtBrush = System.Drawing.Brushes::get_Black();
TxtPen = new System.Drawing.Pen(TxtBrush);

// set text alignment
StringFormat = new System.Drawing.StringFormat();
StringAlignment = System.Drawing.StringAlignment::Center;
StringFormat.set_Alignment(StringAlignment);
StringFormat.set_LineAlignment(StringAlignment);

// init rotation
BarcodeGraphics.TranslateTransform(any2int(dx),0);
BarcodeGraphics.RotateTransform(90);

// draw text
BarcodeGraphics.DrawString(barcodetxt, BarcodeFont,TxtBrush, any2int(dx/2) , any2int(dy/2),StringFormat);

// transfer image to Ax
BarcodeBitmapPtr=BarcodeBitmap.GetHbitmap();
BarcodeImage.importBitmap(BarcodeBitmapPtr);
return BarcodeImage.getData();
}

 
Now make sure you have a report control, type bitmap. Set the newly created display method in the properties.

Tip: Watch out with the ResizeBitmap property.

How to get rid of the report scaling message

When a report doesn’t fit on a page, depending on it’s properties Ax will resize the report. This is a powerful and very useful feature.
Now Ax will inform you that the report has been rescaled (Report is scaled xx percent to fit to page) and this message is generally not well received by users.

Users are annoyed by the message, they get it every time they run the report, they cannot do anything about it, they have to click to close the infolog, …

Ax has a builtin feature to suppress this scaling message. You can modify the init method of your report, and add something like this:

this.printJobSettings().suppressScalingMessage(true);

This is very effective and will do the job.
Only, this requires you to modify every report with these kind of messages.

A nicer way would be if we could switch it off in one place for all reports. Fortunately, this is possible as well.
Go to class SysReportRun, in the Run method, place following code before the call to super:

if(this.printJobSettings())
this.printJobSettings().suppressScalingMessage(true);

void run(boolean onlyReport = false)
{
// If this report is a webReport the run a webReport.
if (webSession() && runBaseReport)
{
runBaseReport.runWebReport();
}
else
{
// When running the report and onlyReport = true then run the report.
if (!onlyReport && runBaseReport)
{
if (runBaseReport.prompt())
{
runBaseReport.run();
}
// If the prompt returns false the do not run the report.
// The RunBaseReport.Run method calls the ReportRun.run method with the parm onlyReport = true.
return;
}
}

this.buildPrintGrandTotal();
this.buildPrintOnlyTotals();

// 30 december 2010
//scaling message suppressed by default
if(this.printJobSettings())
this.printJobSettings().suppressScalingMessage(true);
// 30 december 2010

super();
}

Now we don’t have to modify each and every report and our users are happy.

Note that you can still override the settings in your report. In some reports this is done by default, like SalesInvoice and SalesConfirm.

How to Use a Programmable Section in Reports in Dynamics AX

We can use programmable sections to add any kind of customized information for example : sum of fields in the report .
To activate a programmable section, activate it explicitly with an element.execute(Number) statement. The Number must be specified in the ControlNumber property for the design section.

For example, I’ve created a prgrammable section calculating the sum of a column in dynamics ax .
To call this section , I add the method element.execute(1); in the fetch method after calling super() and before returning the result of the fetch

public boolean fetch()
{
    boolean ret;
    ret = super();
    element.execute(1);
    return ret;
}

How to diplay the total of a column in a report in Dynamics AX

1. To diplay the total of a column (named ColumnA), you have to :

Click on ColumnA and open its properties (Alt+enter)

Modify the SumAll to YES
Create a new field (named ColumnASum) typed Sum
In its properties, modify the dataFieldName to ColumnA
That’s all, the sum of all lines will be diplayed in the field.

Remark : naturally the ColumnASum must be created outside and after the Body containing the ColumnA
For example, you put the ColumnA in the body of a section group in a generated design and the sum of this column in the footer of the section group.

II. You can also calculate the sum of a column following another method : In the classdeclaration, declare a variable : sumnet

In the executeSection method of the body you calculate the sum of your column :

public void executeSection()
{
sumnet=sumnet+tmpPayrolljournaldata_1.PayrollPaytypeAmount4;

super();
}

Then, in the method of your report create a method that displays this variable :

Display Amount _SumNet()
{
return SumNet;
}

In the Grand Total section : Footer of the generated design for example:
create a field and set its DataMethod to _SumNet .
this field calculates the sum of your column.

How to call a report and a report’s menuitem from X++

To call a report, use this code for example, if you need to call a report when clicking on a button :
void clicked()
{
Args args = new args();
ReportRun reportRun;
;
args.name(reportstr(PurchRequisitionDetails));
reportRun = classFactory.reportRunClass(args);
reportRun.init();
reportrun.run();

super();
}

To call a report’s menuitem , use this one :

MenuFunction menuFunction;
;
menuFunction = new MenuFunction(reportStr(Cust), MenuItemType::Output);
menuFunction.create();
menuFunction.run();

How to call different reports from one class in Dynamics AX

I added a Checkbox in the method : Dialog of the class,Via the Checkbox I tried to manage that the
right report is choosen, when it is unchecked , I got the actual report when It is checked I call aonther similar class that returns the appropriate report.After the method prompt, I can get the value of the checkBox in the dialog : true or false then according to the needs I can run the appropriate report.