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