Search This Blog

Monday, 13 October 2014

Displaying Graphs and Charts in Ax 2012 Form

Hi,

I would like to share you how to display data in graphs and charts in AX 2012 Forms

for an example i have displayed the customer details whose invoice amount is greater than 10000 and less than 20000

step 1:

create a new form called CustomerInvoiceAmountGraph

step 2:

add custInvoicaJour table as datasource

step 3 : 

override init() method and class declaration method

public class FormRun extends ObjectRun
{
      Graphics    graphics;
      CustInvoiceJour custinvoiceJourGraphValues;
      Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar chartToolbarControl;
}

public void init()
{
    super();
// create an runtime reference to the toolbar control
   chartToolbarControl = chartToolbarControlHost.control();
// bind the tool bar to the chart control by passing an instance of the chart control to it
    chartToolbarControl.set_ChartControl(graphControl.control());
   this.showchart();
}

step 4:

create a new method called showchart() where your logic is placed to display the customer data
whose invoice amount is greater than 10000 and less than 20000

void showchart()
{

// create an instance of the X++ to .NET abstraction class and bind it to the chart control

    graphics =  new Graphics();
    graphics.ManagedHostToControl(graphControl);

// set your abstracted chart options

    graphics.create();
    graphics.parmTitle("@SYS95906");
    graphics.parmTitleXAxis("CustAccount");
    graphics.parmTitleYAxis("Amount");

// populate the chart with data

while select CustInvoiceJour where  CustInvoiceJour.InvoiceAmount>=10000  && CustInvoiceJour.InvoiceAmount <=20000
    {
        graphics.loadData( CustInvoiceJour.InvoiceAccount,  ' ' , CustInvoiceJour.InvoiceAmount);
    }

    graphics.showGraph();

}

step 5:

Right click Design->New control->ManagedHost

select Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar


step 6:

Right click Design->New control->ManagedHost

select System.Windows.Forms.DataVisualization.Charting.Chart and change the name of the control as GraphControl

output:

Happy Daxing.....

Passing multiple selected record as a parameter form Form to Report

Hi ,

Today i would like to share, how to pass multiple selected record from Form as a parameter to
Report

step 1 : 

write this piece of code in the clicked of the button

void clicked()
{
    CustTable  custTable1;
    container   con;
    Args        args;
    str         multiSelectString;
    args = new Args();
    custTable1= CustTable_ds.getFirst(1);
    while (custTable1)
    {
        // storing recid of selected record in container
        con = conIns(con,1, custTable1.AccountNum);
        // converting container to string with comma separated
        multiSelectString = con2Str(con,',');
        custTable1= CustTable_ds.getNext(); // moves to next record
    }

    // passing string
    args.parm(multiSelectString);
    // calling menu item
    new MenuFunction(menuitemOutputStr(SampleReport), MenuItemType::Output).run(args);
}

step 2 :

write this piece of code in the init method of the report and change the query property userupdate as no



public void init()
{
   str multipleRecords;
    super();
    multipleRecords = element.args().parm();
  this.query().dataSourceTable(Tablenum(CustTable)).addRange(fieldNum(CustTable,AccountNum)).value(multipleRecords);
}

Happy Daxing....

Thursday, 9 October 2014

X++ code to Customize Customer InvoiceId in the format of SI-YYMM#####

Hi ,

I would like to share you , how to customize Customer Invoiceid in the format of SI-YYMM#####

Class used in this process is

SalesInvoiceJournalCreateBase

Method used is

initJournalHeader()

comment this below line

custInvoiceJour.InvoiceId= this.getJournalNumber();

and write the following code :

int HyphenPosition;

 

custInvoiceJour.InvoiceDate = this.updateDate();

 HyphenPosition=strFind(this.getJournalNumber(),'-',1,strLen(this.getJournalNumber()));

    custInvoiceJour.InvoiceId = subStr(this.getJournalNumber(),1,HyphenPosition)+
                                subStr(date2str(custInvoiceJour.InvoiceDate,321,2,0,2,0,2),1,4)+
                                subStr(this.getJournalNumber(),HyphenPosition+1,strLen(this.getJournalNumber())-HyphenPosition);


That's it .......
 

 
 

Friday, 3 October 2014

Execute MenuItems Through Code

Hi ,

Today I would like to share some syntax which is used to execute MenuItems through code

They are three types of Menuitems in AX:

1)Display - Which represents Forms
2)Output - Which represents Reports
3)Action - Which represents Class

Menu Items are represented by the MenuFuction class

Syntax :

MenuFunction menuFunction;
  
menuFunction = new MenuFunction(menuItemDisplayStr(MyDisplayMenuItem), MenuItemType::Display);
menuFunction.run();
 
 
MenuFunction menuFunction;
  
menuFunction = new MenuFunction(menuItemOutputStr(MyOutputMenuItem), MenuItemType::Output);
menuFunction.run();
 
 
MenuFunction menuFunction;
  
menuFunction = new MenuFunction(menuItemActionStr(MyActionMenuItem), MenuItemType::Action);
menuFunction.run();