Search This Blog

Monday, 16 February 2015

X++ code to fetch the fileName from Directory based on Current Company Code

Hi ,

Refer below code which will fetch the filename from Directory (FilePath) based on Current Company Code


 static container findMatchingFiles(
        str _folderPath
    ,   str _filePattern   = '.txt')
{
    System.IO.DirectoryInfo     directory;
    System.IO.FileInfo[]        files;
    System.IO.FileInfo          file;
    InteropPermission           permission;
    str         fileName;
    counter     filesCount;
    counter     loop;
    container   mathchingFiles;
    ;
    permission  = new InteropPermission(InteropKind::ClrInterop);
    permission.assert();
     //BP Deviation Documented
    directory   = new System.IO.DirectoryInfo(_folderPath);
    files       = directory.GetFiles(_filePattern);
    filesCount  = files.get_Length();
    for (loop = 0; loop < filesCount; loop++)
    {
        file            = files.GetValue(loop);
        fileName        = file.get_FullName();
        mathchingFiles  = conins(mathchingFiles, conlen(mathchingFiles) + 1, fileName);
    }
    CodeAccessPermission::revertAssert();
    return mathchingFiles;
}

static FileName fetchFiles(Args _args)
{
    container   files;
    counter     loop;
    FileName         fileName;
  
    str entityId;
   
    Filename filepathVal;
    Filename fileType;
    filename fileNameString;
    ;
    entityId=strLfix('E'+curext(),7,'0');
    files = DNT_DatabasicsUpload::findMatchingFiles(#FilePath, entityId+'*.txt');
    for (loop = 1; loop <= conlen(files); loop++)
    {
   
        filename= conpeek(files, loop);
        return filename;
      
    }
    return #FilePath;
}

Happy Daxing...............

Friday, 13 February 2015

X++ code to import data from text file(.txt) to Ax Tables in Ax 2009

Hi ,

Refer the below X++ code which import data from text file to Ax Tables in AX 2009
 
static void Notepad(Args _args)
{
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
TextIO file;
NotepadTable notepadTable;
container con;
str conitem,conitem1,conitem2;
int i;
#File
 
;

dialog = new Dialog("Notepad Upoad");
dialogFilename = dialog.addFieldValue(extendedTypeStr(FilenameOpen),filename,"File Name");
dialog.filenameLookupFilter([".txt", #AllFiles]);
dialog.filenameLookupTitle("Upload from Text File");
dialog.caption("Upload from text file");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
file = new TextIO(filename, #IO_READ);
file.inRecordDelimiter('\n'); //For Next Record
file.inFieldDelimiter('\t');
ttsbegin;
while(file.status() == IO_STATUS::OK)
{
con = file.read();
conitem = conpeek(con,1);
if(conItem!="0")
{
notepadTable.initValue();
notepadTable.Name=conpeek(con,1);
notepadTable.MathsMark=conpeek(con,2);
notepadTable.PhysicalMark=conpeek(con,3);
notepadTable.insert();
}
 
 
 
}
ttscommit;
         

Monday, 12 January 2015

SSRS Report using UI Builder Class, Contract Class and RDP Class in AX 2012 R2

Hi All,

Today I would like to share you ,how to use UI Builder Class, Contract class and RDP class in SSRS report in Ax 2012 R2?

UI Builder Class Overview

User Interface (UI) Builder Class is used to define the layout of the parameter dialog box that opens before a report is run in Microsoft Dynamics AX. It is used to add the customizations as well as additional fields in the dialog.
Following are the scenarios where UI Builder Class can be used:
  1. Grouping dialog fields
  2. Overriding dialog field events
  3. Adding a customized lookup to a dialog field
  4. Binding dialog fields with Report contract parameters
  5. Changing the layout of the dialog
  6. Adding custom controls to the dialog
To create a UI builder class, extend it with SrsReportDataContractUIBuilder.

Step 1:

Create New Class SRCustomLookupsUIBuilder  which extends SrsReportDataContractUIBuilder

Here I have created one enum called YearEnum in AOT and add the values to the enum dynamically through code .

public class SRCustomLookupsUIBuilder extends SrsReportDataContractUIBuilder
{

DialogField dialogYear;
SRCustomLookUpContract rdpContract;
FormBuildComboBoxControl formComboBoxControl;

}


public void build()
{
int i;

rdpContract = this.dataContractObject();
dialogYear= dialog.addField(EnumStr(YearEnum));

formComboBoxControl=dialogYear.control();
formComboBoxControl.enumType(0);

formComboBoxControl.label("Year");

formComboBoxControl.items(11);

for(i=0;i<=10;i++)
{
formComboBoxControl.item(i+1);

formComboBoxControl.text(int2str(year(systemDateGet())-i));

}

}


public void getFromDialog()
{
super();

formComboBoxControl.item(dialogYear.value()+1);

rdpContract.parmYear(str2int(formComboBoxControl.text()));

}

Step 2:

Create a Temporary Table SalesCountTmp and create the fields listed below




Step 3:

Create New Class SRCustomLookUpContract

[DataContractAttribute,

SysOperationContractProcessingAttribute(classstr(SRCustomLookupsUIBuilder))] 


class SRCustomLookUpContract
{
int yearVal;
}


[DataMemberAttribute('YearBase')]
public int parmYear(int _year = yearVal)

{

yearVal= _year;


return yearVal;



}
Step 4:


Create New Class SRCustomLookupDP which extends SRSReportDataProviderBase


[SRSReportParameterAttribute(classStr(SRCustomLookUpContract))]
class SRCustomLookupDP extends SRSReportDataProviderBase

{

SRCustomLookUpContract contract;

SalesCountTmp salesCountTmp;

}


[SRSReportDataSetAttribute('SalesCountTmp')]
public SalesCountTmp getTmpSRSalesTableDetails()
 
{
 select * from salesCountTmp;
 return salesCountTmp;
}



[SysEntryPointAttribute]
 
public void processReport()
{

Query query;

QueryRun qRun;

QueryBuildRange qbr;

SalesTable salesTable;


date fromdate,todate;

utcDateTime _UtcStartPeriod,_UtcEndPeriod;

int yearval;

contract = this.parmDataContract() as SRCustomLookUpContract;

yearval=contract.parmYear();fromdate=mkDate(1,1,yearval);

todate=mkDate(31,12,yearval);

_UtcStartPeriod=DateTimeUtil::newDateTime(fromdate,0);

_UtcEndPeriod= DateTimeUtil::newDateTime(todate,86400);

query = new Query();

qbr = query.addDataSource(tableNum(SalesTable)).addRange(fieldNum(SalesTable,CreatedDateTime));

 
qbr.value(queryRange( _UtcStartPeriod, _UtcEndPeriod));
 
qRun = new QueryRun(query);

while(qRun.next())
{
salesTable = qRun.get(tableNum(SalesTable));
salesCountTmp.SalesId=salesTable.SalesId;

salesCountTmp.SalesCreatedDateTime=salesTable.createdDateTime;

salesCountTmp.SalesStatus=salesTable.SalesStatus;

salesCountTmp.insert();

}

}


SSRS Report using Controller , Contract and RDP class in Ax 2012 R2 & Validates fromDate and ToDate Value

Hi All,

Today I would like to share you ,  how to create SSRS report using Controller, Contract and RDP class in AX 2012 R2?

Step 1:

Create new Temp Table . Ex: VendTransTemp with below listed table.



Step 2 :

Create a New Class . Ex: SRDemoDP which extends SRSReportDataProviderBase




 
 

[SRSReportParameterAttribute(classStr(SRDemoContract))]
 
class SRDemoDP extends SRSReportDataProviderBase
{
    SRDemoContract contract;
    VendTransTemp  vendTransTmp;
}
 
 
 [SRSReportDataSetAttribute('VendTransTemp')]
public VendTransTemp getTmpVendTransDetails()
{
    select * from vendTransTmp;
    return vendTransTmp;
}
 
 
[SysEntryPointAttribute]
public void processReport()
{

     Query query;

    QueryRun qRun;

    QueryBuildRange qbr,qbr1;

    VendTrans    vendTrans;

    AccountNum vendAccountNum;

    date fromDate,toDate;

    contract = this.parmDataContract() as SRDemoContract;

    vendAccountNum=contract.parmVendAccountNum();

    fromDate=contract.parmfromDate();

    toDate=contract.parmtoDate();

     query =  new Query();

    query.addDataSource(tableNum(VendTrans)).addRange(fieldNum(VendTrans,TransDate)).value(queryRange(fromDate,toDate));
    qRun = new QueryRun(query);

     while(qRun.next())

    {
        vendTrans = qRun.get(tableNum(VendTrans));

        if(vendTrans.AccountNum==vendAccountNum)

        {

            vendTransTmp.AmountMST=vendTrans.AmountMST;

            vendTransTmp.VendAccount=vendTrans.AccountNum;

            vendTransTmp.VendInvoiceId=vendTrans.Invoice;

            vendTransTmp.Voucher=vendTrans.Voucher;

            vendTransTmp.TransDate=vendTrans.TransDate;

            vendTransTmp.insert();

        }
    }
}
 
Step 3:
 
Create a New Class . Ex: SRDemoContract class which implements SysOperationValidatable Interface .
 
 
class SRDemoContract implements SysOperationValidatable

{

AccountNum vendAccountNum;

TransDate formDate,toDate;

}

 
 

[DataMemberAttribute('FromDate')]

 
public FromDate parmfromDate(TransDate _formDate = formDate)

{

formDate= _formDate;
 
return formDate;
 }

 

 

[DataMemberAttribute('ToDate')]
 public ToDate parmtoDate(TransDate _toDate = toDate)

{

toDate= _toDate;
return toDate;

}

 
[DataMemberAttribute('AccountNum')]

public AccountNum parmVendAccountNum(AccountNum _vendAccountNum = vendAccountNum)
{

vendAccountNum= _vendAccountNum;
return vendAccountNum;

}



public boolean validate()
 {
 boolean isValid = true;

if (!formDate)

{
 
isValid = checkFailed("From Date should be entered");

}
 
if (!toDate)
 
{
 
isValid = checkFailed("To Date should be entered");

}
 
if (isValid && (formDate > toDate))
  
{
 
isValid = checkFailed(strfmt("From Date should be less than or equal to To Date", date2StrUsr(formDate, DateFlags::FormatAll), date2StrUsr(toDate, DateFlags::FormatAll)));

}
 
return isValid;

}



Step 4:

 
Create a New Class . Ex: SSRSDemoController class which extends SRSReportRunController.
 




class SSRSDemoController extends SrsReportRunController
{
}
 
protected void prePromptModifyContract()
{

 
VendTable vendTable;

SRDemoContract contract;

FormDataSource fds;
 
//get the reference of the current contract object

contract = this.parmReportContract().parmRdpContract() as SRDemoContract;

vendTable=Args.record();

fds=Args.record().dataSource();

contract.parmVendAccountNum(vendTable.AccountNum);
 

}
 
 
public static client void main(Args args)
{
//define the new object for controller class
SSRSDemoController ssrsDemoController;
 
ssrsDemoController = new SSRSDemoController();

//pass the caller args to the controller
ssrsDemoController.parmArgs(args);
 
//set the report name and report design to run
ssrsDemoController.parmReportName(ssrsReportStr(Controller_SSRS,PrecisionDesign1));

//execute the report
srsDemoController.startOperation();

}
 


Step 5:

Design the report in Visual studio. Add the report to AOT and deploy it

Step 6:

Create Output menuitem for the SSRs Report

Step 7:

Create action menuitem for the controller class . Ex: SSRSDemoController

Step 8 :

Add the menuitem to VendorTableListPage form




Step 9:

Click Vendor Transaction Report Button . A Parameter window open with the selected vendor Account Number.




 
 
 
 
 
  Ouput :