AX 2012 : Unbalanced X++ TTSBEGIN/TTSCOMMIT

Unbalanced X++ TTSBEGIN/TTSCOMMIT


Run this job For get rid of this error

static void _ResetTTS(Args _args)
{
    while (appl.ttsLevel() > 0)
    {
        info( strfmt("Level %1 aborted" ,appl.ttsLevel()));
        ttsAbort;
    }
}

AX 2012 :AxBuild Compilation

AX 2012 Command prompt compilation / AxBuild.exe for Parallel Compile on AOS of X++ to p-code


  • Open CMD with admin Privileges
  • Find out where AX is installed (in My case its C drive)
  • cd to this path : C:\Program Files\Microsoft Dynamics AX\60\Server\(yourServer)\bin
  • check whether AXbuild.exe is present
  • type the below command to CMD (Dont forget to change path if needed)
  • C:\Program Files\Microsoft Dynamics AX\60\Server\(your Server)\bin>
    AxBuild.exe xppcompileall /workers=4 /s=01 /nocleanup /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin"
  • /workers=4  : compilation will schedule into 4 seperate process means 4 CMD will be open
  • /s=01            : How many AX instances you have (I have only 1)
  • add at the end of the above command /log:"C:\temp" if you want create log file after compilation(Optional)
  • Press Enter

AX 2012:Company Logo,Company info

 How to get Comapny Logo and company info using X++  


   TableTmp TableTmp;

    CompanyInfo                  companyInfo = CompanyInfo::find();

    TableTmp.CompanyName      = companyInfo.Name;
    TableTmp.CompanyLogo      = FormLetter::companyLogo();
    TableTmp.CompanyAddress   = companyInfo.postalAddress().Address;
    TableTmp.CompanyPhone     = companyIknfo.phone();
    TableTmp.Rectid           = companyInfo.phoneLocal();

AX 2012: accessing previous value of a field

   Accessing previous value of a field


  *You can try this logic in validate or modified field methods*
            
   DictTable dictTable;
DictField dictField;
tableId tableId;
fieldId fieldId;
#DictField
PurchParmLine purchParmLine;

            if(any2real(this.(_fieldId)) < any2real(this.orig().(_fieldId)))
            {
                
               dicttable = new DictTable(tablenum(PurchParmLine));             
               fieldId   = dictTable.fieldName2Id("ReasonTableRef");
               dictField = dictTable.fieldObject(fieldId);
              // dictField =new DictField(tablenum(PurchParmLine), fieldnum(PurchParmLine,                                  ReasonTableRef));
                if (!dictField.isSystem() && bitTest(dictField.flags(), #dbf_visible)
                && bitTest(dictField.flags(), #dbf_mandatory))
                {
                     info(strfmt("Field number %1 changed from %2 to %3",_fieldId,this.orig().                                          (_fieldId),this.(_fieldId)));
                }
            }

AX 2012:Add MenuItem To Dialogue Box

 Add MenuItem To Dialogue Box

  Write in UI builder Class  build  method


   DialogGroup dlgGrp;
   Dialog      dlg = this.dialog();
  
super();
  
dlgGrp = dlg.addGroup('cutomgroup');
dlg.addMenuItemButton(MenuItemType::Display,menuitemDisplayStr(yourmenuitem),Dia                 logMenuItemGroup::CurrentGrp);

AX 2012: Adding Query range Dynamically

    Query                   query;
    QueryRun                queryRun;
    QueryBuildDataSource    qbds1;
    QueryBuildRange         qbr1, qbr2,qbr3,qbr4;
 
    query = new Query();
    qbds1 = query.addDataSource(tableNum(Table_Name));
    if(Condition)
    {
         qbr1  = qbds1.addRange(fieldNum(Table_Name, Fieldname1));
         qbr1.value("Value");
    }
    if(Condition)
    {
         qbr2  = qbds1.addRange(fieldNum(Table_Name, Fieldname2));
         qbr2.value("Value");
    }
    if(Condition)
    {
         qbr3  = qbds1.addRange(fieldNum(Table_Name, Fieldname2 ));
         qbr3.value("Value");
    }
     if(Condition)
    {
         qbr4  = qbds1.addRange(fieldNum(Table_Name, Fieldname3));
         qbr4.value("Value");
    }
 
    queryRun = new QueryRun(query);

Ax 2012: Lookup with Joins


//This is for lookup with InnerJoin ////Write in Form Level Design>Field>Lookup

public void lookup()
{
   // create the query for the lookup
   Query                   query                = new Query();
   QueryBuildDataSource    cpj;

   QueryBuildDataSource    bol;
   QueryBuildRange         qbr1;

  // Intantiantes a SysTableLookup object telling it which control activated the lookup, and
// what table should be displayed inside the lookup form.(root table)
//"Failed to execute query because no root data source on the form matches the root datasource on            the query"
//This error can occur when the wrong TableId is passed in SysTableLookup::newParameters().
//Make sure you use the table you want to do the lookup in (not the table you're doing for).

   SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(LTCustomerDetails),this);

   cpj   =   query.addDataSource(tablenum(LTCustomerDetails));
   qbr1  = cpj.addRange(fieldnum(LTCustomerDetails,LTCustomerID));

   qbr1.value(queryvalue('3'));

   //Join Table
   bol   = cpj.addDataSource(tablenum(LTPurchaseDetails));
   bol.relations(false);
   bol.joinMode(joinmode::InnerJoin);
   bol.addLink(fieldnum(LTCustomerDetails,LTCustomerID),fieldnum(LTPurchaseDetails,LTCustomerID));

   //Add the query to the lookup form
   sysTableLookup.parmQuery(query);

   // Add fields that will be shown in the lookup as columns
   // Specify the fields to show in the form.
   sysTableLookup.addLookupfield(fieldNum(LTCustomerDetails,LTCustomerID));
   sysTableLookup.addLookupfield(fieldNum(LTPurchaseDetails,LTCustomerName));
 
   // Perform the lookup
   sysTableLookup.performFormLookup();

}

example


public void lookup() //on form level
{
    Query query = new Query();
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildDataSource queryBuildDataSource2;
    QueryBuildRange      queryBuildRange;

    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), this);

    sysTableLookup.addLookupField(fieldNum(InventTable, ItemId));
    sysTableLookup.addLookupField(fieldnum(InventTable,NameAlias));
 
    queryBuildDataSource = query.addDataSource(tableNum(InventTable));
    queryBuildDataSource2   = queryBuildDataSource.addDataSource(tablenum(EcoResProduct));
    queryBuildDataSource2.relations(false);
    queryBuildDataSource2.joinMode(joinmode::InnerJoin);
    queryBuildDataSource2.addLink(fieldnum(EcoResProduct,RecId),fieldnum(InventTable,Product));          
       
    queryBuildRange = queryBuildDataSource2.addRange(fieldNum(EcoResProduct,LTPurchaseOrderType));
    queryBuildRange.value(enum2str(PurchTable.LTPurchaseOrderTypes));


    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

X++: write multiple cases together

Multiple Cases in Switch:


switch (value)
{
   case 1:
   case 2:
   case 3:
      //do some stuff
      break;
   case 4:
   case 5:
   case 6:
      //do some different stuff
      break;
   default:
       //default stuff
      break;
}
More info