Thursday, 29 March 2012

lookup filter on table level on form

make new field on table and drag on form design
Write code on table methods:
//Created by Loveleen on 29/3/2012
public static void lookupNumberSequenceGroup(FormControl _formControl)
{
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tablenum(NumberSequenceGroup), _formControl);
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    ;

    queryBuildDataSource    = query.addDataSource(tablenum(NumberSequenceGroup));
    queryBuildRange         = queryBuildDataSource.addRange(fieldnum(NumberSequenceGroup, Active));
    queryBuildRange.value(queryValue(NoYes::Yes));

    sysTableLookup.addLookupfield(fieldnum(NumberSequenceGroup, numberSequenceGroupId));
    sysTableLookup.addLookupfield(fieldnum(NumberSequenceGroup, description));

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

Call on form datasource field (related)where you want lookup
//Created by Loveleen on 29/3/2012
public void lookup(FormControl _formControl, str _filterStr)
{
    super(_formControl, _filterStr);
    NumberSequenceGroup::lookupNumberSequenceGroup(_formControl);
}

Monday, 19 March 2012

Set AutoSum property on sorting field into Query with x++

static void Job2(Args _args)
{
SysReportRun sysReportRun;
Args args = new Args(reportstr(SysReportAuto));
People people;
SysQueryRun sysQueryRun;
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
Report report;
ReportDesign reportDesign;
 ReportAutoDesignSpecs reportAutoDesignSpecs;
ReportSection reportSection;
Object reportControl;
ReportRealControl reportRealControl;
;  
//Init reportRun sysReportRun = classfactory.reportRunClass(args);
sysReportRun.init();  
//Setup group total field(s) with autoSum and autoHeader
queryBuildDataSource = query.addDataSource( tablenum(people) );
queryBuildDataSource.addSortField( fieldnum(people, Salary) );
queryBuildDataSource.autoSum(1, true); 
//Autosum for 1st sort field
queryBuildDataSource.addSortField( fieldnum(people, MyGroup) );
queryBuildDataSource.autoHeader(2, true); 
//AutoHeader for 2nd sort field //Init queryRun on reportRun
sysQueryRun = new SysQueryRun( query );
sysQueryRun.promptLoadLastUsedQuery( false ); 
// use created queryRun 
  sysReportRun.queryRun( sysQueryRun );  
//Setup and create repor design
  report = sysReportRun.report();
 report.query(sysReportRun.queryRun().query());
reportDesign = report.design();
 reportDesign.caption( 'Test for people' );
reportDesign.reportTemplate( 'FrontPage' );
 reportAutoDesignSpecs = reportDesign.autoDesignSpecs();
 // Add section and fields on the report
  reportSection = reportAutoDesignSpecs.addSection(ReportBlockType::Body, people.TableId); reportControl = reportSection.addControl(people.TableId, fieldnum(people, Name));
 reportControl = reportSection.addControl(people.TableId, fieldnum(people, MyGroup));
 reportControl = reportSection.addControl(people.TableId, fieldnum(people, Salary));
 reportRealControl = reportControl;  
//calculate grand total on this field 
  reportRealControl.sumAll( true );
 reportAutoDesignSpecs.grandTotal( true );
 //Block form usage
sysReportRun.queryRun().query().interactive( false );
 report.interactive( false );  
//Setup print options: //Print ranges, print totals only, print grand total, remove...repetitive, remove ...identical sysReportRun.printRemoveRepeatedHeaders(true);
 sysReportRun.buildPrintRemoveRepeatedHeaders();
 sysReportRun.run();
 }

Monday, 12 March 2012

Creation of new financial dimension



Many a times there is requirement from many customers to create a new financial dimension in AX apart from the three standard dimensions “Department”, “Cost center” and “Purpose”. Here is a step by step description of creating a new financial dimension.
To create a new financial dimension modify following objects one by one
    • Base enum “SysDimension” : Find this base enum and right click on this base enum -> Select option “New element”. In properties window give a name to this element say “TestDim” and label as “Test dimension”. Save the base enum.
    • Extended data type “Dimension” : Find this EDT and then add a new array element in this EDT. Name this array element as “TestDim”. In properties window specify label as “Test dimension”. Now in the “Relations” tab of this new array element add a new “Normal”  relation first. To this normal relation open properties window and set property Table as “Dimensions” and Related field as “Num”. Now add another relation of type “Related field fixed”. To this related field fixed relation open properties window and set Related field as “DimensionCode” and property value as “3″ (this is the value of the new enum element created in SysDimension). Save the EDT.
    • Extended data type “DimensionCriteria” : Repeat the process of modification as done for EDT “Dimension” above.
    • Extended data type “XMLMapDimension” : Find this EDT in AOT and then create a new array element for this EDT. Label this array element as “Test document value”. Save the EDT.
    • Extended data type “MandatoryDimension” : Find this EDT in AOT and then create a new array element for this EDT. Label this array element as “Validate test dimension”. Save the EDT.
    • Extended data type “DimensionLedgerJournal” : Find this EDT in AOT and then create a new array element for this EDT. Label this array element as “Test dimension”. Save the EDT.
    • Extended data type “DimensionKeepFromTransaction” : Find this EDT in AOT and then create a new array element for this EDT. Label this array element as “Keep transaction test dimension”. Save the EDT.
    • Extended data type “COSAllowDimensions” : Find this EDT in AOT and then create a new array element for this EDT. Label this array element as “Test dimension”. Save the EDT.
    • Extended data type “DimensionPriority” : Find this EDT in AOT and then create a new array element for this EDT. Label this array element as “Test dimension”. Save the EDT.
    • Extended data type “DimensionAllocation” : Find this EDT in AOT and then create a new array element for this EDT. Label this array element as “Test dimension”. Save the EDT.
    • Table “LedgerJournalTrans” : Find this table in AOT and add a new relation in the relations tab as follows. Create a new relation in relations tab and name it as say “interCoDimension3″ (You can see three more similar relations with suffix 0, 1 and 2 for three standard dimensions). Now set the property table of this relations as “Dimensions”. Create a new “Normal” relation under this realtion tab and set the property “Field” = “OffsetCompany” and property “RelatedField” = “dataAreaId”. Create another “Normal” relation under this relation tab and set the property “Field” = “InterCoDimension[4]” and property “RelatedField” = “Num”. Now create a new “Related field fixed” relation under this tab and set property “Value” = 3 (this is the value of the new enum element created in SysDimension) and property “Related field” = “DimensionCode”. Save the changes.
The new financial dimension is successfully created in AX and can be viewed in different forms through out the AX where ever dimensions are used.