Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Monday, July 22, 2013

Difference between two dates in days in Dynamic AX

To get the difference between two dates in dynamics ax just convert the dates into numbers and subtract one from the other. The result would be the amount of days between these dates.

today() - mkdate(31,01,2011) ;
or
days = date2num(Date123) - date2num(Date234);
or
TblName.FieldName= date2num(today()) - date2num(AnotherTblName.DatefeildName);


days = date2num(Date123) - date2num(Date234);

To get the difference between two DateTime Values just use the DateTimeUtil Class. The result is the difference in seconds. So just divide these through #secondsPerDay and you'll get the days

#timeConstants

days = DateTimeutil::getDifference(DateTime123, DateTime234) / #secondsPerDay;
-------------------------------------------------------------------
date2num(systemdateget()) - date2num(urtable.date);
---------------------------------------------------------------------------------------------------------
static void DateDiff(Args _args)
{
    TransDate   d1,d2;
    int daysdiff;
    ;
    d1  = 31\12\2010;
    d2  = today();
    daysDiff = d2 - d1;
    info(strfmt("%1",daysDiff));
}
-----------------------------------------------------------------------------------------------------
Or just override the field in datasource level as modified()

then
tablename.fieldName3 = tablename.fieldName2 - tablename.fieldName1;
filedName1 - Out put field,
filedName2 - To date field,
filedName2 - from date field,


Wednesday, July 17, 2013

Save the SSRS report as pdf or print it through code in Dynamic AX

Ax 2012 Reports (SSRS) Print Utilities
This article gives the examples, to print the reports of Dynamics Ax 2012 (SSRS Reports), in different ways.
1)Sending the Ax report through mail.
2)Save the report as file in local computer. (example covered to save the report as .pdf file)
Mail the report

static void myJobPrintReportMail(Args _args)
{
SrsReportRun                        reportRun;
Query                               query;
SRSReportPrintDestinationSettings   SRSReportPrintDestinationSettings;
SRSPrintDestinationSettings         srsPrintSettings;
;
delete_from SRSReportPrintDestinationSettings;
reportRun = new SRSReportRun();
reportRun.reportName(“Vend.Report”);  //<ReportName>.<DesignName>
// Set printersettings
srsPrintSettings = reportRun.printDestinationSettings();
srsPrintSettings.printMediumType(SRSPrintMediumType::Email);
srsPrintSettings.emailTo(“mail@gmail.com”);
srsPrintSettings.emailAttachmentFileFormat(SRSReportFileFormat::PDF);
srsPrintSettings.emailSubject(strfmt(‘vendor report – %1′, systemdateget()));
srsPrintSettings.pack();
reportRun.showDialog(false);
reportRun.init();
reportRun.run();
}
Save the Report To PDF File
static void myJobPrintReportPDF(Args _args)
{
SrsReportRun                        reportRun;
SRSPrintDestinationSettings         srsPrintSettings;
SRSReportPrintDestinationSettings   SRSReportPrintDestinationSettings;
;
delete_from SRSReportPrintDestinationSettings;
reportRun = new SRSReportRun();
reportRun.reportName(“Vend.Report”);  //<ReportName>.<DesignName>
// Set printersettings
srsPrintSettings = reportRun.printDestinationSettings();
srsPrintSettings.overwriteFile(true);
srsPrintSettings.printMediumType(SRSPrintMediumType::File);
srsPrintSettings.fileFormat(SRSReportFileFormat::PDF);
srsPrintSettings.fileName(“D:\\Vendors.pdf”);
srsPrintSettings.pack();
reportRun.showDialog(false);
//reportRun.saveParameters();                         //For Report parameters
reportRun.init();
reportRun.run();
}
In case of Parameterized reports
If the report has parameters (Using Contract Class),
Use the following line, to read the parameters and save to the table called,SRSReportParameters
reportRun.saveParameters();
For the same parameters, provide the required values to run the report.
I have tried the example of Vendor Transactions report, with my customized version. This standard report has 4 parameters, have used same parameters and provided the values inSRSReportParameters table to run the report.
For clear idea, have a quick look in to the following picture.



SQL code to upate one Legal entity banner to all the legal entity in D365

 Hi, update companyimage set  companyimage.Image  = companyimageA.Image  from  ( select Image from companyimage where dataAreaid = 'USF...