Monday, February 24, 2014

How to get Vendor as a Ledger Dimension in AX

Hi Guys,

Below is the code to get the Vendor Account as Ledger Dimension.....

static void getNonLedgerAccounts(Args _args)
{
    LedgerDimensionAccount  ledgerDim;
    ledgerDim = DimensionStorage::getDynamicAccount("VendorAccount", LedgerJournalACType::Vend);
    info(strFmt("%1 -%2", ledgerDim, DimensionAttributeValueCombination::find(ledgerDim).DisplayValue));
}

Monday, February 10, 2014

IIF expression in SSRS reports in Ax


Hi Guys,

Below is the sample code for IIF expression in SSR Reports

Scenario:
if value is 1 then Sunday should be displayed
if value in 2 then Monday should be displayed
if value is 3 then Tuesday should be displayed.

How to achieve this...?

Solution:

Using IIF

=IIf(Fields!TarifeTipiNo.Value = 1, "Sunday", IIf(Fields!TarifeTipiNo.Value = 2, "Monday", IIf(Fields!TarifeTipiNo.Value = 3, "Tuesday", "Wednesday")))

Using Switch:

=Switch(Fields!TarifeTipiNo.Value = 1, "Sunday", Fields!TarifeTipiNo.Value = 2, "Monday", Fields!TarifeTipiNo.Value = 3, "Tuesday")




Get First and Last dates in a Month.

Hi Guys,

Below is the code to get first and last dates in a month in Ax

//First date of a month.
info(strfmt('First date of this month is  %1', mkdate(1,mthofyr(today()),year(today()))));

//Last date of amonth..
info(strfmt('Last date of this month is  %1', endmth(today())));

Export Report to PDF from Code

Hi Guys,

Below is the code to Export Report to PDF from Code in Ax

Create the Instance of the SrsReportRun class

SRSReportRun rr = new SRSReportRun("ReportName");
rr. init();

//change the report printing destination as follow

// print to file

           rr.printDestinationSettings().printMediumType(SRSPrintMediumType::File);
// file type
            rr.printDestinationSettings().fileFormat(SRSReportFileFormat::PDF);
// overwrite the file or not
            rr.printDestinationSettings().overwriteFile(true);
// give the file name
            rr.printDestinationSettings().fileName(filePath);
// if u want to print all the pages set to true else false
            rr.printDestinationSettings().printAllPages(false);
// if u want to print specified pages set the page ranges
            rr.printDestinationSettings().fromPage(PageNo);
            rr.printDestinationSettings().toPage(PageNo);
// run the report
rr.run();

Wednesday, February 5, 2014

How to Run a Job from Code in AX

Hi Guys...

Below is the code to Run a Job from code using menuitem in AX....
Args  args;
args  =  new Args();
args.name(identifierStr("Your Job Name"));
new MenuFunction(MenuitemActionStr("Your Job Name") , MenuItemType::Action).run(args);

Different ways of Opening a Form from Code in AX

Hi Guys..

Below are few ways to call a Form in AX using X++ code.....

Calling a form Using Menuitem.
Args args = new Args();
args.record(myArgumentRecord);
args.caller(this);
new MenuFunction(menuItemOutputStr(MyDisplayMenuItem), MenuItemType::Display).run(args);
Calling Form Using FormRun.
static void OpenFormByCodeB()
{
FormRun formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
if we change the type of formRun from class FormRun to class Object, we can implement and execute extra methods on our destination form.This helps us to call extra customizations .

static void OpenFormByCodeB()
{
Object formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.callyourmethodhere();
formRun.run();
formRun.wait();
}
we can also pass records as parameters in the above code...
static void CallLedgerBudgetForm(Args _args)
{
    LedgerTable                             ledgerTable;
    BudgetModelId                           modelId;
    Args                                    args;
    FormRun                                 formRun;
    FormDataSource                          fds;
    QueryBuildDataSource                    qbds;
    QueryBuildRange                         qbr;
    ;
    select LedgerTable where LedgerTable.AccountNum == '110110' ;
    ModelId= 'SUb1';
    args = new Args(formstr("LedgerBudget"));
    args.record(LedgerTable);
    formRun = classfactory.formRunClass(args);
    formRun.init();
    fds = formRun.dataSource();
    qbds = fds.query().dataSourceTable(tablenum(LedgerBudget));
    qbr = qbds.addRange(fieldnum(LedgerBudget,ModelNum));
    qbr.value(queryvalue(modelId));
    qbr.status(RangeStatus::Hidden);
    formRun.run();
    formRun.wait();
}

Hope this helps you guys.......






Monday, February 3, 2014

List of All Functions in AX 2012

Hi Guys....

Below is the MSDN Link for the Different Functions in AX 2012...

Functions in AX 2012

MutliSelection of records on a Grid in AX

Hi Guys.....

Below is the Code to retrieve the Selected records on a Grid......

First make sure that the MultiSelect  Property for the Button Control is set to YES.

then  write the below code in the clicked method to get the list of selected records..

void clicked()
{
CustTable Customers;

super();

//getFirst method gets all the selected records in the grid
Customers = CustTable_ds.getfirst(true);
while (Customers)
{
info(strfmt("You selected Customer %1",Customers.AccountNum));
// get the next selected record
Customers = CustTable_ds.getNext();
}
}

How to Open a Table from Code

Hi Guys...

Below is the code to Open a Table from X++ code....

static void OpenTable(Args _args)
{
SysTableBrowser sysTableBrowser = new SysTableBrowser();

;
//Browse Customers
sysTableBrowser.run(tablenum(CustTable ));
}

Date functions in AX

Below are some of the Date Functions......

Static Void dateFunctions(Args  _args)
{
Transdate dt;

;
dt = today();

info(strfmt('Date - %1',dt));

//Gets the month for the given date...
info(strfmt("Month - %1",mthofYr(dt)));

/Gets the month name from the given date...
info(strfmt("Month Name - %1",mthname(mthofYr(dt))));

//Gets the day for the given date...
info(strfmt("Day - %1",dayOfMth(dt)));

//Gets the day name from the given date...
info(strfmt("Day Name - %1",dayname(dayOfMth(dt))));

//Gets the year for the given date...
info(strfmt("Year - %1",year(dt)));

//Gets the current weekday number from the date...
info(strfmt("Weekday number - %1",dayOfwk(dt)));

//Gets the day of the year from the given date...
info(strfmt("Day of year - %1",dayOfyr(dt)));

/Gets the week of the year from the given date...
info(strfmt("Week of the year - %1",wkofyr(dt)));

//Gets the date after 2 months from given date
info(strfmt("Date after 2 months - %1",dateMthFwd(dt,2)));

}