Wednesday, 20 July 2016

Customer Tax information through x++ in ax 2012

static void CustomerTaxInfo(Args _args)
{
    CustTable                   custTable;
    LogisticsLocation      logisticsLocation;
    DirPartyLocation       dirPartyLocation;
    TaxInformation_IN    taxInformation_IN;
 
    select custTable where custTable.AccountNum=="US-027"
        join dirPartyLocation where dirPartyLocation.Party == custTable.Party
            join logisticsLocation where logisticsLocation.RecId == dirPartyLocation.Location
                join taxInformation_IN where taxInformation_IN.RegistrationLocation ==                       logisticsLocation.RecId ;
 
 
    info(strFmt("Service Tax Number - %1 Tax Type - %2", TaxRegistrationNumbers_IN::find(taxInformation_IN.STCRegistrationNumberTable).RegistrationNumber,TaxRegistrationNumbers_IN::find(taxInformation_IN.STCRegistrationNumberTable).TaxType));
    info(strFmt("Sales Tax Number - %1 Tax Type - %2",TaxRegistrationNumbers_IN::find(taxInformation_IN.SalesTaxRegistrationNumber).RegistrationNumber,TaxRegistrationNumbers_IN::find(taxInformation_IN.SalesTaxRegistrationNumber).TaxType));

    info(strFmt("Tax Number(TIN) - %1 Tax Type - %2",TaxRegistrationNumbers_IN::find(taxInformation_IN.TIN).RegistrationNumber,TaxRegistrationNumbers_IN::find(taxInformation_IN.TIN).TaxType));

    info(strFmt("Tax Account Number(TIN) - %1", TaxWithholdRegNumbers_IN::find(taxInformation_IN.TAN).RegistrationNumber));

GST

info(strFmt("GST- %1 Tax Type - %2", TaxRegistrationNumbers_IN::find(taxInformation_IN.GSTIN).RegistrationNumber,TaxRegistrationNumbers_IN::find(taxInformation_IN.GSTIN).TaxType));
     
}

Monday, 11 July 2016

Reference Lookup for Customer Delivery Address


















  • Create a Table with fields CustAccount, LogisticsPostalAddress(int64)
  • maintain relation :  Table.LogisticsPostalAddress == LogisticsPostalAddress.Recid.
  • Create a new form and add above data source
  • Under Design, Take NewControl stringedit for CustAccount 
  • override lookup 

public void lookup()
{
    Query query = new Query();
    QueryBuildDataSource         qbds;
    QueryBuildRange                 queryBuildRange;
    SysTableLookup                   sysTableLookup;
    super();

    sysTableLookup         =  sysTableLookup::newParameters(tableNum(CustTable), this);
    sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum), true);
    qbds   = query.addDataSource(tablenum(CustTable));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

}
  • then Again Take NewControl Reference group 
  • Set Properties for reference group

























  • Override LookupReference 

public Common lookupReference()
{
    CustTable                   custTable;
    DirPartyTable               dirPartyTable;
    DirPartyLocation            dirPartyLocation;
    LogisticsPostalAddress      logisticsPostalAddress;
    SysReferenceTableLookup     sysRefTableLookup;
    Query                       lookupQuery = new Query();
    QueryBuildDataSource        lookupQueryDataSource;

    // Construct the SysRefTableLookup object
    sysRefTableLookup = SysReferenceTableLookup::newParameters(tableNum(LogisticsPostalAddress), ReferenceGroup);

    // Add the field list that will be displayed on the lookup form
   // You can Change/Add more fields in lookup based on your requirement.

    sysRefTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Address));
    sysRefTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Location));

    // Construct the query's data source
    lookupQueryDataSource = lookupQuery.addDataSource(tableNum(LogisticsPostalAddress));

 // To add multiple values in range.
    while select  Location from LogisticsPostalAddress
        join DirPartyLocation
        join dirPartyTable
        join custTable
            where logisticsPostalAddress.Location == dirPartyLocation.Location
                && dirPartyLocation.Party == custTable.Party
                && custTable.Party == DirPartyTable.RecId
                && custTable.AccountNum == CustomerName.valueStr()
    {
        // Add ranges to the query data source
        lookupQueryDataSource.addRange(fieldNum(LogisticsPostalAddress, Location)).value(queryValue(LogisticsPostalAddress.Location));
    }


    // Pass the query to the lookup object
    sysRefTableLookup.parmQuery(lookupQuery);

    return sysRefTableLookup.performFormLookup();
}
  • Save and Run the Form

Tuesday, 5 July 2016

Interaction Class in Ax 2012

Interaction Class

                           Interaction class contain some x++ logic to handle user interactions and make buttons or other controls visible or enabled.

                              To achieve more control over how your model driven list pages behaves, you can specify a custom interaction class by using interactionclass property of the form. The name of your class end with Listpageinteraction. It should inherits from SysListPageInteractionBase.

  •   Interaction class extends SysListPageInteractionBase class.
  •   Here we are having override methods

Initializing           :  Called when the form is initializing – Similar to the form init method
intializeQuery          :  Also called when the form is initializing – Similar to the datasource init method
selectionChanged   :   Called when the active record changes – Similar to the datasource active method.
setButtonEnabled   :  Should be overridden to dynamically enable/disable buttons based on the current selection. This is called from the selectionChanged method.
setButtonVisibility  : Shows or hides grid fields. This method is called once when the forms opens


  • difference between interaction classes and normal classes?

              The interaction classes are extending a base ListPageInteraction class. This has some methods supported by the kernel to interact e.g. with initializations of the list page form. Other classes can be build stand alone to execute e.g. a batch process or represent a web service or posting classes.

SelectionChanged 
Syntax
public void selectionChanged()
{
    TableName TableBuffer = this.listPage().activeRecord(queryDataSourceStr(QueryName, DataSourceName));
    Super();
    if(Condition)   //like - if(TableBuffer.fieldName == Something)
    this.listPage().actionPaneControlEnabled(formControlStr(FormName, ControlName),true);
}

Example:-
public void selectionChanged()
{
    Requisition requisition = this.listPage().activeRecord(queryDataSourceStr(RequisitionQuery,Requisition_1));
    super();
   
    if(requisition.WorkflowApprovalStatus == WorkflowApprovalStatus::Approved)
        this.listPage().actionPaneControlEnabled(formControlStr(RequisitionListPage,Edit),true);
    else
        this.listPage().actionPaneControlEnabled(formControlStr(RequisitionListPage,Edit),false);
}