Tuesday, December 9, 2014

Business/Working days in AX

Following job is to calculate business days/working days in AX using base calendars.

In my case base calendar name is "24/5" you can change it as per your setup.

static void businessdaysInPeriod(Args _args)
{
    WorkCalendarSched workCalendarSched;
    date start;
    date end;
    counter workingdays;
    counter totaldays;
    CalendarId primCalendar="24/5";
    ;

    start = str2date("21-11-2014",123);
    end   = str2Date("26-11-2015",123);

    workCalendarSched = new workCalendarSched();

    while(start<=end)
    {
        totaldays++;

        if(workCalendarSched.isdateopen(primCalendar,start)==true)
        {
            workingdays++;
        }
        start++;
    }

    info(strfmt("Total days: : %1",totaldays));
    info(strfmt("Total working days: : %1",workingdays));

}

2 comments:

  1. Hi Faisal can i use this to find the total working days between Delivery date and Start date of a sales order, For a report?

    ReplyDelete
  2. This post helped me find the base AX method. It should probably be used:

    info(strFmt("%1", WorkCalendarCalculator::calcDuration(start, end, primCalendar)));

    ReplyDelete

I will appreciate your comments !

How to enable new Microsoft teams - Public Preview!

New Microsoft Teams is just AWESOME, quick but useful post below shows how you have this preview feature to make your life EASY!  Open Micr...