Tuesday 28 January 2014

Deploy the all default reports [AX 2012] ,error 105: Unable to resolve the server's DNS address

Deploy the default reports [AX 2012]

Hi,
Open Windows PowerShell as an administrator by following these steps:
·         Click Start > Administrative Tools.
·         Right-click the Microsoft Dynamics AX 2012 Management Shell option.
·         Click Run as administrator.
In the Windows PowerShell
Publish-AXReport -ReportName CustTransList
Above code is to deploy specific report
Below code to deploy list of reports
Publish-AXReport -ReportName CustTransList, CustTransOpenPerDate
To deploy all reports, enter the following command:
Publish-AXReport –ReportName *

error 105: Unable to resolve the server's DNS address

Hi,

Start > All Programs > Accessories > Command Prompt. Right click on it and 'Run as Administrator'. Type the following and hit enter: ipconfig /flushdns


Wednesday 22 January 2014

Model importing and exporting through command prompt in ax 2012:



For model importing:
Go to run-cmd
  cd C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities
enter
C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>
axutil import /file:”C:\irfanmodel.axmodel” /config: MicrosoftDynamicsAX /conflict:PUSH /createparents:ON
enter
y
y

then model is successfully imported
here Irfanmodel.axmodel- is our model
MicrosoftDynamicsAX-instance name(services/server aos/client configuration instance name)


For exporting command:
Go to run-cmd
  cd C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities
enter
C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>
axutil export /model:irf /file:C:\irfamodel.axmodel /config: MicrosoftDynamicsAX
Enter
Y
Y
Here in irf – is our using model from where should we want data model
Irfamodel.axmodel-destination file in c drive
MicrosoftDynamicsAX-instance name


While doing model import /export make sure that command having same spaces and case sensitive






Export an .axmodel file (Windows PowerShell)
1.     On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
2.     At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
Windows PowerShell
Export-AXModel –Model <name> -File <Filename.axmodel> -Details
This example exports the specified model to a file that has the specified file name.
You can use the -Key parameter to specify the strong-name key pair file to use to sign a model.
For more information, see Export-AXModel.
3.     You can also use the Sign Tool to sign the file with a digital certificate, or the AXUtil genlicense command to Authenticode sign a file. For more information, see:
o    Sign Tool
Export an .axmodel file (AXUtil)
1.     On the Start menu, click Command prompt.
2.     Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.
3.     At the command prompt, type the following command, and then press ENTER.
4.  axutil export /model:<modelname> /file:<filename> /verbose
This example exports the specified model to a file that has the specified file name.
You can use the [/key:SNK-file] parameter to specify the strong-name key pair file to use to sign a model.


Import an .axmodel file (Windows PowerShell)
1.     On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
2.     At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
Windows PowerShell
Install-AXModel -File <Filename.axmodel> -Details
This command installs the specified file in the same layer that it was exported from.
By default, you will be prompted to install the model based on whether it has been signed. The following table describes the prompts shown.
Scenario
Prompt
The model file is not signed.
The model is not signed. Are you sure you want to install this model (Y/N)?
The publisher is recognized from the digital certificate.
The model is signed by ‘{0}’”. Would you like to continue (Y/N)?
The publisher was not available from the digital certificate.
The certificate for the model was not recognized. Are you sure you want to install this model (Y/N)?
The provider for the certificate is unknown.
The certificate for the model was not recognized. Are you sure you want to install this model (Y/N)?
If the installation fails because of a conflict, we recommend that you rerun the cmdlet, and use the -Conflict Push option to push the element that has the conflict to the related update layer. You can then resolve the conflict. For more information, see How to: Resolve Conflicts After Importing a Model.
For more information, see Install-AXModel.
Import an .axmodel file (AXUtil)
1.     On the Start menu, click Command prompt.
2.     Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.
3.     At the command prompt, type the following command, and then press ENTER.
axutil import /file:<filename> /verbose

Thursday 16 January 2014

lookup types and adding range ,adding more datasources

public void lookup(FormControl _formControl, str _filterStr)
{
    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(ProdBOM), _formControl);
    Query query = new Query();
    QueryBuildDataSource qbds;
    QueryBuildRange  qbr;
    ;
    sysTableLookup.addLookupField(fieldnum(ProdBOM, itemid));
    sysTableLookup.addLookupMethod('itemName');
    qbds = query.addDataSource(tablenum(ProdBOM));
    if(Rejection_ProdId.valueStr())
    {
        qbds.addRange(fieldnum(ProdBOM, prodid)).value(Rejection_ProdId.valueStr());
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}




public void lookup()
{
    Query                   query = new Query();
    QueryBuildDataSource    qbdsItem;
    QueryBuildDataSource    qbdsInventTableModule;
    QueryBuildDataSource    qbdsInventItemLocation;
    QueryBuildRange         qbrModuleType;
    SysMultiTableLookup     sysTableLookup;
    ;
    qbdsItem = query.addDataSource(tableNum(InventTable));
    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Purch");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Purch));
  
    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Invent");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);           
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Invent));
          
    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Sales");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Sales));
          
    qbdsInventItemLocation = qbdsItem.addDataSource(tableNum(InventItemLocation));
    qbdsInventItemLocation.relations(true);
    qbdsInventItemLocation.fetchMode(QueryFetchMode::One2One);
          
    sysTableLookup = SysMultiTableLookup::newParameters(this, query);
          
    sysTableLookup.addLookupField(fieldNum(InventTable, ItemId));
    sysTableLookup.addLookupField(fieldNum(InventTable, ItemName));
    sysTableLookup.addLookupMethod(tableMethodStr(InventTable, ConfigActive), 1, "Is configuration active?");
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 2, false, "Purch Item Tax Group");
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 3);
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 4);
    sysTableLookup.addLookupField(fieldNum(InventItemLocation, CountGroupId), 5);
    sysTableLookup.performFormLookup();
}


public void lookup()

{
//super();


// Declaration
Query   LookupQuery    =   new Query();

QueryBuildDataSource     LookupQueryBuildDataSource;

QueryBuildRange                  LookupQueryBuildRange;
SysTableLookup CustomSysTableLookup =       SysTableLookup::newParameters(tableNum(CustTable), this);

;

// Add fields that you want in Lookups

CustomSysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));

CustomSysTableLookup.addLookupField(fieldNum(CustTable,Name));

LookupQueryBuildDataSource =

LookupQuery.addDataSource(tableNum(CustTable));

LookupQueryBuildRange=

LookupQueryBuildDataSource.addRange(fieldNum(CustTable,AccountNum));

//LookupQueryBuildRange.value(queryValue(NOYESCOMBO::Yes));

// Execute the Query

CustomSysTableLookup.parmQuery(LookupQuery);

CustomSysTableLookup.performFormLookup();
}

public void lookup(FormControl _formControl, str _filterStr)
{
SysTableLookup sysTableLookup; // systemclass to create //customlookup
Query query;
QueryBuildDataSource qbd;
;
sysTableLookup = SysTableLookup::newParameters(
tablenum(InventTable),
_formcontrol);

// Construct query on the table,
// whose records you want to show as lookup.
query = new Query();
qbd = query.addDataSource(tablenum(InventTable));
qbd.addRange(fieldnum(InventTable,ItemType)).value(SysQuery::value(enum2str
(ItemType::Item)));

// add the fields to the lookup list
sysTableLookup.addLookupfield(fieldnum(InventTable,ItemId));
sysTableLookup.addLookupfield(fieldnum(InventTable,ItemName));

// pass the query as parameter
// system will show the records in the lookup
// as per your query
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

}

public void lookup()
 {
     //This lookup basis the list criteria on information in 2 tables
     //All display fields come from Table1, Table2 is used for limiting criteria
    
     //super();
    
     //This Next Line initializes the the sysTableLookupClass
     sysTableLookup          sysTableLookup  =
                     SysTableLookup::newParameters(tableNum(<TABLENAME1>), this);
    
     Query                   query           = New Query();
     QueryBuildDataSource    qbdsTbl1, qbdsTbl2;
     QueryBuildRange         qbr;
     ;
    
     //Add Tables to the data source
     qbdsTbl1      = query.addDataSource(tableNum(<TABLENAME1>));
     qbdsTbl2     = qbdsTbl1.addDataSource(tableNum(TABLENAME2));


     //Add Query Ranges to limit List records  
     qbr = qbdsTbl1.addRange(fieldNum(<TABLENAME1>,<RANGEFIELDNAME1>));
     qbr.value(<CRITERIAVALUE>);

     qbr = qbdsTbl1.addRange(fieldNum(<TABLENAME1>, <RANGEFIELDNAME2>));
     qbr.value(<CRITERIAVALUE>);

     qbr = qbdsTbl1.addRange(fieldNum(<TABLENAME1>, <RANGEFIELDNAME3>));
     qbr.value(<CRITERIAVALUE>);
    
     //Since we have multiple tables in the query turn on relations
     qbdsTbl1.relations(true);

     //Add Ranges to the Table2
     qbr = qbdsTbl2.addRange(fieldNum(<TABLENAME2>, <RANGEFIELDNAME4>));
     qbr.value(<CRITERIAVALUE>);
    
     qbdsTbl2.relations(true);

     //The next 2 lines actualy adds the fields that will be displayed in the lookup grid
     sysTableLookup.addLookupfield(fieldNum(<TABLENAME1>, <DISPLAYFIELDNAME>));
     sysTableLookup.addLookupfield(fieldNum(<TABLENAME1>, <DISPLAYFIELDNAME>));
    
     //Hand the created query to the sysTableLookupClass
     sysTableLookup.parmQuery(query);

     //Display the drop down
     sysTableLookup.performFormLookup();

 }




Another example single table with field and table names instead of variable place holders



//Single table example with actual table and field names instead of  place holders
 public void lookup()
 {
     //This lookup basis the list criteria on information in 2 tables
     //super();
     sysTableLookup          sysTableLookup  =
                 SysTableLookup::newParameters(tableNum(salesBillOfLadingJournalTable), this);
     Query                   query           = New Query();
     QueryBuildDataSource    qbdsJT, qbdsBLR;
     QueryBuildRange         qbr;
     ;

     qbdsJT      = query.addDataSource(tableNum(salesBillOfLadingJournalTable));
     qbdsBLR     = qbdsJT.addDataSource(tableNum(salesBLReservation));



     qbr = qbdsJT.addRange(fieldNum(salesBillOfLadingJournalTable,isMaster));
     qbr.value(enum2str(noYes::No));

     qbr = qbdsJT.addRange(fieldNum(salesBillOfLadingJournalTable, custAccount));
     qbr.value((salesBillOfLadingJournalTableMaster.CustAccount));

     qbr = qbdsJT.addRange(fieldNum(salesBillOfLadingJournalTable, masterBLID));
     qbr.value(&quot;&quot;&quot;&quot;);

     qbdsJT.relations(true);

     qbr = qbdsBLR.addRange(fieldNum(salesBLReservation, blOpen));
     qbr.value(enum2str(noYes::Yes));
     qbdsBLR.relations(true);

     sysTableLookup.addLookupfield(fieldNum(salesBillOfLadingJournalTable, BillOfLadingID));
     sysTableLookup.addLookupfield(fieldNum(salesBillOfLadingJournalTable, salesID));
     sysTableLookup.parmQuery(query);

     sysTableLookup.performFormLookup();

 }








Look up filter using enum value in Dynamic AX


void lookupJobId(FormControl control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId), true);
    sysTableLookup.addLookupMethod(tablemethodstr(InventTable, ItemName), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable    ,ABCValue));
    queryBuildRange.value(enum2str(ABC::A)); //Example of Enum value

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

    // Perform lookup
    sysTableLookup.performFormLookup();
}
/***************************************************************/
If the filter with reference to the enum field already existing in form then.


void lookupJobId(FormControl control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId), true);
    sysTableLookup.addLookupMethod(tablemethodstr(InventTable, ItemName), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable    ,ABCValue));
//Direct filter for enum ABC::A
    queryBuildRange.value(enum2str(ABC::A)); //Example of Enum value
//else
//consider the enum fields is stored in header table as HeaderTableName.EnumField
//Make sure that EnumField should be ABC enum

    queryBuildRange.value(enum2str(str2enum(ABC,HeaderTableName.EnumField)));

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

    // Perform lookup
    sysTableLookup.performFormLookup();

}















Few of the table name changes in ax 2009 to ax 2012



InventSize       : EcoResSize, EcoResProductMasterSize

InventColor    :  EcoResColor, EcoResProductMasterColor

ConfigTable    : EcoResConfiguration,
                         EcoResProductMasterConfiguration,

InventDim (InventColorId, InventSizeId, ConfigIdfields)        : EcoResProductDimensionAttribute


InventDimCombination :  EcoResProductVariantSize ,
                                       EcoResProductVariantColor,
                                       EcoResProductVariantConfiguration




LedgerTable To MainAccounts in ax 2012

LedgerTrans to General Journal Tables in ax 2012

GeneralJOurnalAccountEntry
GeneralJournalEntry
SubledgerVoucherGeneralJournalEntry
LedgerEntry(Optional)
LedgerEntryJournal(Optional)
LedgerEntryJournalizing(Optional)

Complete select statement
This pattern and example demonstrate how to select the general journal records that replace a single
LedgerTrans record.

Example
select RecId from generalJournalAccountEntry
join RecId from generalJournalEntry
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
join RecId from subledgerVoucherGeneralJournalEntry
where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry ==
generalJournalEntry.RecId
outer join RecId from ledgerEntry
where ledgerEntry.GeneralJournalAccountEntry == generalJournalAccountEntry.RecId
outer join RecId from ledgerEntryJournal
where ledgerEntryJournal.RecId == generalJournalEntry.LedgerEntryJournal
outer join RecId from ledgerEntryJournalizing
where ledgerEntryJournalizing.GeneralJournalAccountEntry ==
generalJournalAccountEntry.RecId

Select for a specific transaction date
This pattern and example demonstrate how to select the general journal records for a specific
transaction date.

Example
select RecId from generalJournalAccountEntry
join RecId from generalJournalEntry
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
&& generalJournalEntry.AccountingDate == <transaction date input>

Select for a specific voucher and transaction date 
This pattern and example demonstrate how to select the general journal records for a specific voucher
and transaction date

Example
select RecId from generalJournalAccountEntry
join RecId from generalJournalEntry
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
join RecId from subledgerVoucherGeneralJournalEntry
where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry ==
generalJournalEntry.RecId
&& subledgerVoucherGeneralJournalEntry.Voucher == <voucher input>
&& subledgerVoucherGeneralJournalEntry.VoucherDataAreaId == <voucher data area ID
input>
&& subledgerVoucherGeneralJournalEntry.AccountingDate == <transaction date input>

find the first and last day of month


DateStartMth and dateEndMth in ax 2012

    1.public date dateStartMth(date _date)

    2.client server public static date dateEndMth(date transDate)

Date and UTCDateTime interval for previous month

This code calculates the first and last date of the previous month

static void EP_dateMonthInterval(Args _args)

{
   date            fromDate;
   date            toDate;
   date            baseDate = systemDateGet();
    ;
    toDate      = dateStartMth(baseDate) - 1;
    fromDate    = dateStartMth(toDate);
    info(strFmt("%1 - %2", fromDate, toDate));
}

UtcDateTime version of the same job
static void EP_UtcdateMonthInterval(Args _args)
{
    UtcDateTime     fromDate;
    UtcDateTime     toDate;
    UtcDateTime     baseDate = DateTimeUtil::utcNow();
    ;
    // Remove this month number of days.
    toDate = DateTimeUtil::addDays(baseDate,-(DateTimeUtil::day(baseDate) -1));
    // Add the rest of this days time minus one second.
    toDate = DateTimeUtil::addSeconds(toDate, -(DateTimeUtil::time(toDate)+1));
    // Remove the number of days we are on in
    // the previous month and add one second to
    // get to the first of the month.
    fromDate = DateTimeUtil::addSeconds(DateTimeUtil::addDays(
    toDate, -(DateTimeUtil::day(toDate))), 1);
    info(strFmt("%1 - %2", fromDate, toDate));
}

When working with dates for a range in a SQL select statement, you may be in need for the first and the last day of a certain month.  What at first seems a bit difficult to calculate (not all the months have the same number of days for example), is pretty easy to accomplish with the right tools.
The first day of a month
You can fool around with things like mkdate, so something like this:
static void FirstOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate FirstOfMth;
   ;

   FirstOfMth=mkdate(1,mthofyr(TransDate),year(TransDate));

   info(date2str(FirstOfMth,123,2,2,2,2,4));
}

But there is a readily available function in the Global class, albeit somewhat
hidden:DateStartMth.
So your code could read like this:
static void FirstOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate FirstOfMth;
   ;
   FirstOfMth=DateStartMth(TransDate);

   info(date2str(FirstOfMth,123,2,2,2,2,4));
}

The last day of a month
Just like with the first day of a month, we have a function that will do the
job for us: endmth
This function calculates the last date in the month of the date specified.
static void LastOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate LastOfMth;
   ;

   LastOfMth=endmth(TransDate);

   info(date2str(LastOfMth,123,2,2,2,2,4));

}