Monday, 20 November 2017

SSRS: Convert Seconds into hours minutes & second H:M:S

I came across a scenario in which i need to convert total number of seconds into hours minutes and second, so after searching and trying different things i end up with the following visual studio expression which give me my desired result.


=FLOOR(SUM(Fields!Travel.Value)/3600) & ":"
& RIGHT("0"&((SUM(Fields!Travel.Value) MOD 3600)/60),2) & ":"

& Right("0" & RIGHT("0"&(SUM(Fields!Travel.Value) MOD 3600),2) MOD 60,2)



In Above Expression you need to replace Travel with your tmp table field which contains total no. of second.

Thursday, 14 September 2017

AX: get list of years between two dates

To get the list of years between two dates, Below sample code is do the trick:

static void getYearsByDates(Args _args)
{
    date            fromDate;
    date            toDate;
    int             fromyear;
     int            toyear;
     List           yearList;
     ListIterator   iterator;
   
        yearList = new List(Types::String);

   
        fromDate     = mkDate(7,1,2009);
        toDate       = mkDate(10,2,2015);
        fromyear     = year(fromDate);
        toyear      = year (toDate);
        while (fromyear <= toyear)
        {
           yearList.addEnd(int2str(fromyear));
            ++fromyear;
        }
          iterator = new ListIterator(yearList);
        while(iterator.more())
        {
            info(strFmt("year = %1", iterator.value()));
            iterator.next();
        }
   

}

Wednesday, 6 September 2017

AX : Get company Related Data

Today we would see how to retrieve company related data Like Company Name Address, Phone, Fax and Logo. Mostly we need these information when working on SSRS Reports. Below is the sample code how to achieve this :
CompanyInfo     Company;

    Company = CompanyInfo::find();

    SalesGatePassReportTmp.CompanyName       = Company.Name;
    SalesGatePassReportTmp.CompanyAddress    = Company.postalAddress().Address;
    SalesGatePassReportTmp.CompanyPhone      = Company.phone();
    SalesGatePassReportTmp.CompanyFax        = Company.teleFax();

   SalesGatePassReportTmp.Logo                       = CompanyImage::find(Company.dataAreaId, Company.TableId, Company.RecId).Image;

where Logo field in Tmp table is container & extends by Bitmap EDT

Tuesday, 5 September 2017

AX: Get Record Starts With Any Specific Letter

I came across a scenario in which I need to update the those customer records which starts with any particular Letter Let’s suppose Letter  ‘T’ in my case, Below Job is used to update the sales district of all customer account starts with Letter ‘T’.

static void UpdateCustSalesDistrictStartsWith_TK(Args _args)
{
    CustTable           custTable;
    CustAccount         customerAccountStartsWith;
    smmSalesDistrictId  salesDistrict;
    int                 records;

    customerAccountStartsWith ='T';
    salesDistrict = North;

       while select forupdate custTable
              where custTable.AccountNum like customerAccountStartsWith +"*"
              {
                  records++;
                  ttsbegin;
                    custTable.SalesDistrictId = salesDistrict;
                    custTable.doupdate();
                  ttscommit;

              }
           info(strFmt("Total Records updated = %1", records));

}

Sunday, 3 September 2017

AX: Convert Amount to Amount In Words

In Dynamics Ax, There are certain condition happens in which we need to convert the amount into Amount in words. Below Job will assists you to achieve this :

static void ConvertAmountInWords(Args _args)
{
    real    _amount;
     int             amount;
    str             amount2Words;
    _amount =4123456;

    amount       = real2int(round(_amount , 1));
    amount2Words = Global::numeralsToTxt(amount);
    amount2Words = subStr(amount2Words,5,strLen(amount2Words)-4);
    amount2Words = subStr(amount2Words,strLen(amount2Words)-10,-strLen(amount2Words));
    amount2Words = strUpr(amount2Words) + ' ONLY';

    info(strFmt("%1", amount2Words));

}