Home

Thursday, May 29, 2014

Add Numbers on form through button click with help of class in Ax

1-Create a table Addition
  add three integer fields
  S3Add ,ValueB & valueC.


2-Create a  Addition form
  Add adition table as a data source

create a ActionPane Tab and add a menu item button on it

Take a grid

Drag and drop all fields in grid

3-Create a class with name FormAddition write following code
 class FormAddition
{
    Addition  a,s;
    ValueB    b;
    ValueC    c;
    S3Add     sa;
    Args       args;


}

public void run(RecId _recid)
{
    ;
    ttsbegin;
    select  forupdate a where a.RecId == _recid;
    {
       sa = a.ValueB+ a.ValueC;
       a.S3Add = sa;
       a.update();
       // a.insert();
       info(strfmt("ADD- %1,%2,%3",a.S3Add,a.ValueB, a.ValueC));

    }
    ttsCommit;
    // if u want to update use select forupdate a in line 5
 }

public static void main(Args args)
{
    Addition   ad,adloc;
    Object     Addition_DS;
    FormAddition FormAddition = new FormAddition();
    RecId   recidloc;
    ;


    if (args.record().TableId == tablenum(Addition))
    {
        ad = args.record();
        recidloc = ad.RecId;
        FormAddition.run(recidloc);
    }
    Addition_DS = ad.dataSource();
    Addition_DS.reread();
    Addition_DS.refresh();
}

4-Create a menu item button  with Action Type
callon form with help of meny item button


you can download XPO file from my google drive from this link:Class For Sum







What are the classes involved in Journal, Sales order Invoice, Purchase order invoice posting?

Journal Posting: LedgerJournalCheckPost
Sales Order Posting: SalesFormLetter, SalesFormLetter_Invoice

Purchase Order Posting: PurchFormLetter, PurchFormLetter_PurchOrder, PurchFormLetter_ReceiptList, PurchFormLetter_PackingSlip, PurchFormLetter_invoice

Differences between different versions of AX (AX 4.0 , AX 2009 and AX 2012)

How to print an Item with its Size, Color and Configuration in AX 2009

static void PrintItemWithConfigSizeColor(Args _args)
{
    InventTrans         _inventTrans;
    InventDim           _inventDim;
    ;

    while select * from _inventTrans join  _inventDim group by _inventTrans.ItemId ,_inventDim.InventColorID, _inventDim.InventSizeId,_inventDim.configId
                                                               where _inventDim.inventDimId == _inventTrans.inventDimId
        {
            print _inventTrans.ItemId;
            print _inventDim.InventColorId;
            print _inventDim.InventSizeId;
            print _inventDim.configId;

         }
         Pause;
}

Tuesday, May 27, 2014

Open report o button click Ax 2009 which take record from the form

1-Write following code on form button clicked Event
void clicked()
{
    Args args;
    ReportRun reportRun;
    ;
    //breakpoint;
    args = new Args();
    args.name(Reportstr(RejectionStatusLine));
    args.parm(RejectionLine.ProdId);
    args.record(RejectionLine);
    args.parmObject( args );
    reportRun = classfactory.reportRunClass(args);
    reportRun.init();
    reportRun.run();

}
=====================================================================
2-Write following code in Report
public class ReportRun extends ObjectRun
{
    companyInfo companyInfo;
   Rejection  rejection;
}
---------------------------------------------------------------------------------------------------------
public void init()
{
      S3Rejection S3Rejection;
      ;
//    element.initFromArgs(element.args());
//
//   // info(rejection.ProdId);
//    this.query().dataSourceNo(1).addRange(fieldnum(S3Rejection,prodid)).value(rejection.ProdId);
//    super();
      if( element.args())
    {
       S3Rejection.prodid =  element.args().parm();
       S3RejectionLine = element.args().record();

      // info(strfmt('date requested:%1,date confirmed:%2',dateRequested,dateConfirmed));
       this.query().dataSourceNo(1).addRange(fieldnum(S3RejectionLine,prodId)).value(S3RejectionLine.ProdId);
   }

}
---------------------------------------------------------------------------------------------------------
void initFromArgs(Args args)
{

    if (args && args.dataset())
    {
        switch(args.dataset())
        {
            case tablenum(S3Rejection) :
                rejection = args.record();
                break;
        }
    }
}
------------------------------------------------------------------------------------------------------
//BP Deviation documented
display GiroNum  companyGiro()
{
    return companyInfo.Giro;
}

//BP Deviation documented
display Bitmap companyLogo()
{
    return FormLetter::companyLogo();
}


//BP Deviation documented
display Phone emailID()
{
    return companyInfo::find().Email;
}

//BP Deviation documented
display Name companyName()
{
    return CompanyInfo::find().Name;
}


//BP Deviation documented
display Addressing  companyAddress()
{;
    return  CompanyInfo::find().Address;
}

//BP Deviation documented
display  Phone  companyPhone()
{
    return CompanyInfo::find().Phone;
}

//BP Deviation documented
display TeleFax  companyTelefax()
{
    return CompanyInfo::find().TeleFax;
}

display public str ABC_TodaysDate()
{
    return date2Str(today(), 123, DateDay::Digits2, DateSeparator::Slash, DateMonth::Digits2, DateSeparator::Slash, DateYear::Digits4);
}

display int pages()
{
    return  element.pagesTotal();
}

//BP Deviation documented
display timeOfDay startTime()
{
    return element.startTime();
}


//BP Deviation documented
display str 20 pageNum()
{
    return strfmt(element.design().lookupLabel(literalstr("%1 of")), element.page());
}

Display the data on the title bar


Code to disply the emp_id on the title bar of the form

Path : MyEmplForm-->Data Sources-->MyEmplTable-->Methods-->active()


public int active()
{
    int  ret;
    ret  = super();
    element.design().caption(EmpLeaveDetails.Emp_Id);
    return  ret;
}

Sunday, May 25, 2014

Simple UI Builder Class InSSRS Report in AX 2012


The UI Builder class is a class which help you to customize your dialog which pop ups
when you open a report. UI builder Class also help you to add run time lookups and other controls
like combobox,textbox,etc on the dialog form.

This UI Builder class is simple class with less code and less effort. UI Builder Class is needed when you want to customize your dialog which pop ups when you open a Report. UI Builder Class helps you to add run time lookups and other controls on the dialog form.

Step1 : Your Class must extends SrsReportDataContractUIBuilder
class SimpleDemoUIBuilder extends SrsReportDataContractUIBuilder
{
DialogField dialogEmplId;
DialogField dialogName;
boolean enable;
SimpleDemoContract contract;
}// two fields emplId and Name will reflect in the lookup in dialog form at the time of report opening.
Step2 : Override the build method
public void build()
{
contract = this.dataContractObject();
dialogEmplId = this.addDialogField(methodStr(SimpleDemoContract, parmEmplId),contract);
}// this method used for adding the field  which is from contract class.
Step3 : Write this below code to get lookup
private void emplIdLookup(FormStringControl emplIdlookup)
{
Query query = new Query();
QueryBuildDataSource qbds_EmplTable;
SysTableLookup sysTableLookup;
// Create an instance of SysTableLookup with the current calling form control.
sysTableLookup = SysTableLookup::newParameters(tableNum(FilterDemo), emplIdlookup);
// Add fields to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(FilterDemo,EmplId));
sysTableLookup.addLookupfield(fieldNum(FilterDemo,Name));
qbds_EmplTable = query.addDataSource(tableNum(FilterDemo));
sysTableLookup.parmQuery(query);
// Perform the lookup
sysTableLookup.performFormLookup();
}
Step4 : Override this method
public void getFromDialog()
{
contract = this.dataContractObject();
super();
}
Step5 : Override this method
public void initializeFields()
{
contract = this.dataContractObject();
}
Step6 : Override this method
public void postBuild()
{
super();
dialogEmplId = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(SimpleDemoContract,parmEmplId));dialogEmplId.registerOverrideMethod(methodStr(FormStringControl, lookup),
methodStr(SimpleDemoUIBuilder,emplIdLookup), this);dialogEmplId.lookupButton(2);
}

Wednesday, May 21, 2014

Some important question and answers on forms in axapta

Q)when you open the form - what methods/calling sequences?
Ans:init(), run(), executequery()

Q)When you close the form?
Ans:canclose()- boolean, close()
Ok command buton - closeok(), canclose(), close()

Q)when you create a new record?
Ans:Ctrl + n, create of ds, initvalue() of ds, initvalue() of table

Q)how do you do filteraions on the forms?
Ans: Executequery and use queryBuildRange

Q)Enabling and  disabling controls ? 
Ans:active method of data source

Q)How  do you link the datasources on the form??
Ans: join source and link type property

Q)How many link types are available on the datasource??
Ans:delayed, active, passive, inner join, exists join, non exists join, outer join
Splitters [sysformsplitter_x, y, z]

Q)How  to you pass values from one form to another form
-Ans: menuitemButton
- Args[formrun]

Q)what is args class??
Ans:Args is arguments class which will help to pass values from one form to another, object to object
args.parm() - str, args.record[table buffer]
args.caller()
Formrun class in combination with args will help to open  the  form using code
formrun.init(). run(), wait(). or detach().

Interview question and answer for Data dictionary in Axapta

Table - collection of rows and columns

EDT(Extended datatype) - Inheritance, code easy readability, lookups,- 2 RELAtions [Normal and RFF [where clause]

example : select * from custtable - is normal

select * from custtable where gender == female is RFF

How to add columns to the Lookups [Index, Titlefield1, 2 or autolookups]

Q) How to get lookups??

In 3 ways

- EDT, AutoLookup,Relations

Q) what is base enum???

Set of literals or constants which will never change

- example [week - s,s,m,t,....] enums are stored as integers and max - 250

can be accessed by using :: [scope resolution]

Indexes

why do we use index ?- faster performance in select queries
Not to allow duplicates
FieldName Followed by Idx = AccountNoIdx
Field groups:
Autoreport - ctrl + p
Autolookup
almost all the fields should fall under a fieldgroup - on the forms - field groups will form as Group control

Relations on table :
How one table is related or linked to another
Normal - CustTable.accno == custTrans.accno
RFF - paid == custTrans.paid [secondary table on enums]
FF - custTable.gender == male [primary table on enums]

Methods on table:


initvalue(),validatefield(),validatewrite(),modifiedfield(),validatedelete(),delete(),update(),insert()

forcible inserts/delete/updates
dodelete()
doinsert()
doupdate()


Macros:      macros are reusable components,  macros will reduce lines of code
pre-processor
no debugging
faster as they are already compiled
3 ways  - local macro, aot-,macro library
can we pass values to macro ? yes  

Definition of Maps in Ax

Maps can unify the access to similar columns and methods that are present in multiple tables.

Maps are elements that wrap table objects at run time. We can associate a map field with a field in one or more tables. This association enables to use the same field name to access fields with different names in different tables.

Map methods enable us to Create or Modify methods that act on the map fields

Wednesday, May 14, 2014

Dynamically insert Received quantity by Forward quantity in new line

1- Create three Edt with real data type
     -> S3ErrorQty
     ->  S3RecivedQty
     ->  S3ForwardQty

2 Create new table with name RejectionTable
with fields   S3ErrorQty,S3RecivedQty,S3ForwardQty

3- write a static method in tables's method node
   static int64 Returns()
{
    RejectionTable rejectionTable;
   ;
    select reverse firstOnly s3ForwardQty from RejectionTable;
    return rejectionTable.S3ForwardQty;
}

4- Create Form with data source RejectionTable

5 -write methods on form data source S3ErrorQty-modified
public void modified()
{
    super();
    RejectionTable.S3ForwardQty= RejectionTable.S3RecivedQty-RejectionTable.S3ErrorQty;
}
6-write methods on form data source S3RecivedQty-modified
 public void modified()
{
    super();
    RejectionTable.S3ForwardQty= RejectionTable.S3RecivedQty-RejectionTable.S3ErrorQty;
}
7-write create method in form's datasources-RejectionTable-Create
 public void create(boolean _append = false)
{
    super(_append);
    RejectionTable.S3RecivedQty =RejectionTable::Returns();
}



   
 

Calculator class in Ax

1-Create two Edt with real data type
     value1 & value2

2- Create Base Enum S3_Calculator with elements
   Addition,Mul,Sub,Div.

3- Write following class
public class S_Calculator extends RunBaseBatch
{
    DialogField dFvalue1,dFvalue2,dialogType;
    DialogGroup  dlgGrp;
    DialogEnumComboBox  dialogEnumComboBox;
    S3_Calculator    calloc;
    real value1,value2,total;
    str v1,v2;
    int Valueloc1;
    //#define.FieldNoTmp(600)
}

public real add()
{
    ;
    total =this.parmValue1() + this.parmValue2();
    info(strFmt("Add = %1", total));

    return total;

}
 Object dialog()
{
   DialogRunbase   dialog = super();
    ;
    dFvalue1 = dialog.addField(extendedTypeStr(Value1), "value 1");
    dFvalue2 = dialog.addField(extendedTypeStr(Value2), "value 2");

    dialogType = dialog.addField(enumStr(S3_Calculator), "Select the operation");

    return dialog;

}

public real divide()
{
    ;
    total =this.parmValue1() /  this.parmValue2();
    info(strFmt("Division : %1", total));
    return total;
}

public boolean getfromdialog()
{
    boolean ret;

    value1 = dFvalue1.value();
    value2 = dFvalue2.value();
    calloc = dialogType.value();
   /* if (dialogEnumComboBox)
    {
        S3_Calculator = dialogEnumComboBox.selection();
    }*/

    return super();
}

public real multiple()
{
  ;
    total =this.parmValue1() * this.parmValue2();
    info(strFmt("Multiply : %1", total));
    return total;
}

private real parmValue1()
{
    //value1 = dFvalue1.value();
    return value1;
}

private real parmValue2(real _value2 = value2)
{
    //value2 = dFvalue2.value();
    return value2;
}

public void run()
{
    //super();
    Dialog      dialog;
    DialogField  field;
   ;

    dialog = new Dialog("Calculator");
    dialog.addText("Select your values:");
    dFvalue1 = dialog.addField(extendedTypeStr(Value1), "Value 1");
    dFvalue2 = dialog.addField(extendedTypeStr(Value2),  "Value2");
    dialogType = dialog.addField(enumStr(S3_Calculator), "Select the operation");

    dialog.run();
    if (dialog.closedOk())
    {

        info(strFmt("value =  %1,value =  %2",dFvalue1.value(),dFvalue2.value()));
        value1 = dFvalue1.value();
        value2 = dFvalue2.value();
        calloc = dialogType.value();
        if(value1 == 0 && value2 == 0)
        {
            Error ("Please fill the values other than zero");
            break;
        }

        if(calloc == S3_Calculator::Addition)
        {
            this.add();
        }
        if(calloc == S3_Calculator::Mul)
        {
            this.multiple();
        }
        if(calloc == S3_Calculator::Sub)
        {
            this.subtract();
        }
        if(calloc == S3_Calculator::Div)
        {
            if( value2 != 0)
            {
                this.divide();
            }
            else
            {
                info(strFmt("You can not divide with %1",value2));
            }
        }
    }
    else
    {
        dialog.close();
    }

}

Private real subtract()
{
     ;
    total =this.parmValue1() - this.parmValue2();
    info(strFmt("subtract = %1", total));
    return total;

}

public static void main(Args args)
 {
    S_Calculator calc   = new S_Calculator();
     ;

    calc.run();

 }

Tuesday, May 6, 2014

Copy data in text file in ax

static void DataToTxtFile(Args _args)
{
    TextIO file;
    container line;
    InventTable invenTable;
    #define.filename('d:\\items.txt')
    #File
    ;
    file = new TextIO(#filename, #io_write);
    if (!file || file.status() != IO_Status::Ok)
    {
        throw error("File cannot be opened.");
    }
    file.outFieldDelimiter(';');// for semicolon seperator
    while select invenTable
    {
        line = [invenTable.ItemId,invenTable.ItemName,invenTable.ItemGroupId];
        file.writeExp(line);
    }
}