web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Reading table BatchJob.recurrenceData EDT SysRecurrenceData

(0) ShareShare
ReportReport
Posted on by 157

Below find to X++ objects:

(1) Class_OSISysRecurrenceReader.xpo

(2) Job_OSISysRecurrenceReaderJob

     The job is used to demonstrate how to use the class.

---- Class follows ----

Exportfile for AOT version 1.0 or later
Formatversion: 1

***Element: CLS

; Microsoft Dynamics AX Class: OSISysRecurrenceReader unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #OSISysRecurrenceReader
    PROPERTIES
      Name                #OSISysRecurrenceReader
      Origin              #{541DBFDD-8D6E-4430-90DA-F1F38B693EAF}
    ENDPROPERTIES
   
    METHODS
      SOURCE #classDeclaration
        #/// <summary>
        #/// OSISysRecurrenceReader class is used to read batch job recurrence info.
        #/// </summary>
        #/// <remarks>
        #/// Created by Kwarner
        #/// </remarks>
        #
        #class OSISysRecurrenceReader
        #{
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_Caption
        #public static str getBatchInfo_Caption(container c)
        #{
        #    return conPeek(c,2);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_GetStatus
        #public static str getBatchInfo_GetStatus(container c)
        #{
        #    return conPeek(c,1);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_LogLevel
        #public static str getBatchInfo_LogLevel(container c)
        #{
        #    return conPeek(c,3);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_NextStartDate
        #public static str getBatchInfo_NextStartDate(container c)
        #{
        #    return conPeek(c,9);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_NextStartDateTime
        #public static str getBatchInfo_NextStartDateTime(container c)
        #{
        #    return conPeek(c,8);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_NextStartTime
        #public static str getBatchInfo_NextStartTime(container c)
        #{
        #    return conPeek(c,10);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_OrigStartDate
        #public static str getBatchInfo_OrigStartDate(container c)
        #{
        #    return conPeek(c,6);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_OrigStartDateTime
        #public static str getBatchInfo_OrigStartDateTime(container c)
        #{
        #    return conPeek(c,5);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_OrigStartTime
        #public static str getBatchInfo_OrigStartTime(container c)
        #{
        #    return conPeek(c,7);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_Recurrence
        #public static str getBatchInfo_Recurrence(container c)
        #{
        #    return conPeek(c,13);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_RecurrenceEnd
        #public static str getBatchInfo_RecurrenceEnd(container c)
        #{
        #    return conPeek(c,12);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_RuntimeJob
        #public static str getBatchInfo_RuntimeJob(container c)
        #{
        #    return conPeek(c,4);
        #}
      ENDSOURCE
      SOURCE #getBatchInfo_TimeZone
        #public static str getBatchInfo_TimeZone(container c)
        #{
        #    return conPeek(c,11);
        #}
      ENDSOURCE
      SOURCE #getBatchInfoByCaption
        #public static container getBatchInfoByCaption(BatchCaption batchCaption)
        #{
        #    BatchJob batchJob;
        #
        #    select RecId from batchJob where batchJob.Caption == batchCaption;
        #    return OSIBase::getBatchInfoByRecId(batchJob.RecId);
        #}
      ENDSOURCE
      SOURCE #getBatchInfoByRecId
        #public static container getBatchInfoByRecId(RecId batchJobRecId)
        #{
        #    SysRecurrenceData recurrenceData;
        #    utcdatetime       recurrenceDataStartDateTime;
        #    date              recurrenceDataStartDate;
        #    TimeOfDay         recurrenceDataStartTime;
        #    int               recurrenceType;
        #    str               recurrenceTypeStr;
        #    str               recurrenceRepeatStr;
        #    str               recurrenceRepeatCnt;
        #    int               recurrenceRepeatCntInt;
        #    str               recurrenceRepeatDay;
        #    Timezone          recurrenceTZ;
        #    utcdatetime       startDateTime;
        #    date              startDate;
        #    TimeOfDay         startTime;
        #    recId             batchHeaderId;
        #    BatchCaption      caption;
        #    BatchLogLevel     logLevel;
        #    boolean           runtimeJob;
        #    container         results;
        #    container         conTmp;
        #    container         ConWeekDay;
        #    int i, dayOfWeekInt, weekOfMonthInt, monthInt;
        #    str monthInterval, weekOfMonth, dayOfWeek, month;
        #    str dayOfWeekStr, weekOfMonthStr, monthStr;
        #    BatchJob batchJob;
        #
        #    select batchJob where batchJob.RecId == batchJobRecId;
        #    if(batchJob)
        #    {
        #        batchHeaderId = batchJob.RecId;
        #        startDateTime = batchJob.OrigStartDateTime;
        #        startDate = batchJob.StartDate;
        #        startTime = batchJob.StartTime;
        #        recurrenceData = batchJob.RecurrenceData;
        #        caption = batchJob.Caption;
        #        logLevel = batchJob.LogLevel;
        #        runtimeJob = batchJob.RuntimeJob;
        #
        #        recurrenceDataStartDateTime         = SysRecurrence::getRecurrenceStartDateTime(recurrenceData);
        #        recurrenceDataStartDate             = SysRecurrence::getRecurrenceStartDate(recurrenceData);
        #        recurrenceDataStartTime             = SysRecurrence::getRecurrenceTime(recurrenceData);
        #        recurrenceTZ                        = SysRecurrence::getRecurrenceTimezone(recurrenceData);
        #        recurrenceType                      = conpeek(recurrenceData, 4);
        #        recurrenceTypeStr = '';
        #        switch (recurrenceType)
        #        {
        #            case 1:
        #                recurrenceTypeStr = 'No end';
        #                break;
        #            case 2:
        #                recurrenceTypeStr = strFmt('End after %1 iterations', conpeek(recurrenceData, 5));
        #                break;
        #            case 3:
        #                recurrenceTypeStr = strFmt('End after %1 date', conpeek(recurrenceData, 6));
        #                break;
        #        }
        #        recurrenceRepeatStr = conpeek(recurrenceData, 7);
        #        //0 = Minutes
        #        //1 = Hours
        #        //2 = Days
        #        //3 = Weeks
        #        //4 = Months
        #        //5 = Years
        #
        #        if (recurrenceRepeatStr == '0')
        #        {
        #            recurrenceRepeatCnt = conpeek(recurrenceData, 8);
        #            recurrenceRepeatStr = strFmt('Repeat every %1 minutes', recurrenceRepeatCnt);
        #        }
        #        if (recurrenceRepeatStr == '1')
        #        {
        #            recurrenceRepeatCnt = conpeek(recurrenceData, 8);
        #            recurrenceRepeatStr = strFmt('Repeat every %1 hours', recurrenceRepeatCnt);
        #        }
        #        if (recurrenceRepeatStr == '2')
        #        {
        #            conTmp = conpeek(recurrenceData, 8);
        #            if (conpeek(conTmp, 1) == 1)
        #            {
        #                recurrenceRepeatCnt = conpeek(conTmp, 2);
        #                recurrenceRepeatStr = strFmt('Repeat every %1 days', recurrenceRepeatCnt);
        #            }
        #            else
        #            {
        #                recurrenceRepeatStr = 'Repeat every day';
        #            }
        #        }
        #        if (recurrenceRepeatStr == '3')
        #        {
        #            conTmp = conpeek(recurrenceData, 8);
        #            recurrenceRepeatCnt = conpeek(conTmp, 1);
        #            recurrenceRepeatStr = strFmt('Repeat every %1 weeks', recurrenceRepeatCnt);
        #            recurrenceRepeatCnt = conpeek(conTmp, 2);
        #            recurrenceRepeatCntInt = str2int(recurrenceRepeatCnt);
        #            i = 0;
        #            if (recurrenceRepeatCntInt - 64 >= 0)
        #            {
        #                i = i + 1;
        #                ConWeekDay = conIns(ConWeekDay, i, 'Sunday');
        #                recurrenceRepeatCntInt = recurrenceRepeatCntInt - 64;
        #            }
        #            if (recurrenceRepeatCntInt - 32 >= 0)
        #            {
        #                i = i + 1;
        #                ConWeekDay = conIns(ConWeekDay, i, 'Saturday');
        #                recurrenceRepeatCntInt = recurrenceRepeatCntInt - 32;
        #            }
        #            if (recurrenceRepeatCntInt - 16 >= 0)
        #            {
        #                i = i + 1;
        #                ConWeekDay = conIns(ConWeekDay, i, 'Friday');
        #                recurrenceRepeatCntInt = recurrenceRepeatCntInt - 16;
        #            }
        #            if (recurrenceRepeatCntInt - 8 >= 0)
        #            {
        #                i = i + 1;
        #                ConWeekDay = conIns(ConWeekDay, i, 'Thursday');
        #                recurrenceRepeatCntInt = recurrenceRepeatCntInt - 8;
        #            }
        #            if (recurrenceRepeatCntInt - 4 >= 0)
        #            {
        #                i = i + 1;
        #                ConWeekDay = conIns(ConWeekDay, i, 'Wednesday');
        #                recurrenceRepeatCntInt = recurrenceRepeatCntInt - 4;
        #            }
        #            if (recurrenceRepeatCntInt - 2 >= 0)
        #            {
        #                i = i + 1;
        #                ConWeekDay = conIns(ConWeekDay, i, 'Tuesday');
        #                recurrenceRepeatCntInt = recurrenceRepeatCntInt - 2;
        #            }
        #            if (recurrenceRepeatCntInt - 1 >= 0)
        #            {
        #                i = i + 1;
        #                ConWeekDay = conIns(ConWeekDay, i, 'Monday');
        #                recurrenceRepeatCntInt = recurrenceRepeatCntInt - 1;
        #            }
        #
        #            if (conFind(ConWeekDay, 'Monday') > 0)
        #                recurrenceRepeatStr = recurrenceRepeatStr + ' Monday';
        #            if (conFind(ConWeekDay, 'Tuesday') > 0)
        #                recurrenceRepeatStr = recurrenceRepeatStr + ' Tuesday';
        #            if (conFind(ConWeekDay, 'Wednesday') > 0)
        #                recurrenceRepeatStr = recurrenceRepeatStr + ' Wednesday';
        #            if (conFind(ConWeekDay, 'Thursday') > 0)
        #                recurrenceRepeatStr = recurrenceRepeatStr + ' Thursday';
        #            if (conFind(ConWeekDay, 'Friday') > 0)
        #                recurrenceRepeatStr = recurrenceRepeatStr + ' Friday';
        #            if (conFind(ConWeekDay, 'Saturday') > 0)
        #                recurrenceRepeatStr = recurrenceRepeatStr + ' Saturday';
        #            if (conFind(ConWeekDay, 'Sunday') > 0)
        #                recurrenceRepeatStr = recurrenceRepeatStr + ' Sunday';
        #        }
        #
        #        if (recurrenceRepeatStr == '4')
        #        {
        #            conTmp = conpeek(recurrenceData, 8);
        #            if (conpeek(conTmp, 1) == 1)
        #            {
        #                recurrenceRepeatCnt = conpeek(conTmp, 3);
        #                recurrenceRepeatDay = conpeek(conTmp, 2);
        #                recurrenceRepeatStr = strFmt('Repeat every %1 Months on %2 day', recurrenceRepeatCnt, recurrenceRepeatDay);
        #            }
        #            else
        #            {
        #                dayOfWeek = conpeek(conTmp, 5);
        #                monthInterval = conpeek(conTmp, 6);
        #                weekOfMonth = conpeek(conTmp, 4);
        #
        #                dayOfWeekInt = str2int(dayOfWeek);
        #                if (dayOfWeekInt == 1)
        #                    dayOfWeekStr = 'Monday';
        #                if (dayOfWeekInt == 2)
        #                    dayOfWeekStr = 'Tuesday';
        #                if (dayOfWeekInt == 3)
        #                    dayOfWeekStr = 'Wednesday';
        #                if (dayOfWeekInt == 4)
        #                    dayOfWeekStr = 'Thursday';
        #                if (dayOfWeekInt == 5)
        #                    dayOfWeekStr = 'Friday';
        #                if (dayOfWeekInt == 6)
        #                    dayOfWeekStr = 'Saturday';
        #                if (dayOfWeekInt == 7)
        #                    dayOfWeekStr = 'Sunday';
        #
        #                weekOfMonthInt = str2int(weekOfMonth);
        #                if (weekOfMonthInt == 0)
        #                    weekOfMonthStr = '1st';
        #                if (weekOfMonthInt == 1)
        #                    weekOfMonthStr = '2nd';
        #                if (weekOfMonthInt == 2)
        #                    weekOfMonthStr = '3rd';
        #                if (weekOfMonthInt == 3)
        #                    weekOfMonthStr = '4th';
        #                if (weekOfMonthInt == 4)
        #                    weekOfMonthStr = 'last';
        #
        #                recurrenceRepeatStr = strFmt('Repeat every %1 months %2 week on %3', monthInterval, weekOfMonthStr, dayOfWeekStr);
        #            }
        #        }
        #        if (recurrenceRepeatStr == '5')
        #        {
        #            conTmp = conpeek(recurrenceData, 8);
        #            if (conpeek(conTmp, 1) == 1)
        #            {
        #                recurrenceRepeatStr = strFmt('Repeat once per year', recurrenceRepeatCnt, recurrenceRepeatDay);
        #            }
        #            else
        #            {
        #                dayOfWeek = conpeek(conTmp, 3);
        #                weekOfMonth = conpeek(conTmp, 2);
        #                month = conpeek(conTmp, 4);
        #
        #                dayOfWeekInt = str2int(dayOfWeek);
        #                if (dayOfWeekInt == 1)
        #                    dayOfWeekStr = 'Monday';
        #                if (dayOfWeekInt == 2)
        #                    dayOfWeekStr = 'Tuesday';
        #                if (dayOfWeekInt == 3)
        #                    dayOfWeekStr = 'Wednesday';
        #                if (dayOfWeekInt == 4)
        #                    dayOfWeekStr = 'Thursday';
        #                if (dayOfWeekInt == 5)
        #                    dayOfWeekStr = 'Friday';
        #                if (dayOfWeekInt == 6)
        #                    dayOfWeekStr = 'Saturday';
        #                if (dayOfWeekInt == 7)
        #                    dayOfWeekStr = 'Sunday';
        #
        #                weekOfMonthInt = str2int(weekOfMonth);
        #                if (weekOfMonthInt == 0)
        #                    weekOfMonthStr = '1st';
        #                if (weekOfMonthInt == 1)
        #                    weekOfMonthStr = '2nd';
        #                if (weekOfMonthInt == 2)
        #                    weekOfMonthStr = '3rd';
        #                if (weekOfMonthInt == 3)
        #                    weekOfMonthStr = '4th';
        #                if (weekOfMonthInt == 4)
        #                    weekOfMonthStr = 'last';
        #
        #                monthInt = str2int(month);
        #                if (monthInt == 1)
        #                    monthStr = 'January';
        #                if (monthInt == 2)
        #                    monthStr = 'Feburary';
        #                if (monthInt == 3)
        #                    monthStr = 'March';
        #                if (monthInt == 4)
        #                    monthStr = 'April';
        #                if (monthInt == 5)
        #                    monthStr = 'May';
        #                if (monthInt == 6)
        #                    monthStr = 'June';
        #                if (monthInt == 7)
        #                    monthStr = 'July';
        #                if (monthInt == 8)
        #                    monthStr = 'August';
        #                if (monthInt == 9)
        #                    monthStr = 'September';
        #                if (monthInt == 10)
        #                    monthStr = 'October';
        #                if (monthInt == 11)
        #                    monthStr = 'November';
        #                if (monthInt == 12)
        #                    monthStr = 'December';
        #
        #                recurrenceRepeatStr = strFmt('Repeat every year on %1 week of %2 on %3', weekOfMonthStr, monthStr, dayOfWeekStr);
        #            }
        #        }
        #
        #        results = ['Batch Job Found', caption, strFmt('%1', logLevel), strFmt('%1', runtimeJob), strFmt('%1', recurrenceDataStartDateTime), strFmt('%1', recurrenceDataStartDate), strFmt('%1', recurrenceDataStartTime), strFmt('%1', startDateTime), strFmt('%1', startDate), strFmt('%1', startTime), strFmt('%1', recurrenceTZ), strFmt('%1', recurrenceTypeStr), strFmt('%1', recurrenceRepeatStr)];
        #    }
        #    else
        #    {
        #        results = ['Batch Job Not Found', '', '', '', '', '', '', '', '', '', '', '', ''];
        #    }
        #
        #    return results;
        #}
      ENDSOURCE
    ENDMETHODS
  ENDCLASS

***Element: END

---- Job follows ----

Exportfile for AOT version 1.0 or later
Formatversion: 1

***Element: JOB

; Microsoft Dynamics AX Job: OSISysRecurrenceReaderJob unloaded
; --------------------------------------------------------------------------------
  JOBVERSION 1
 
  SOURCE #OSISysRecurrenceReaderJob
    #static void OSISysRecurrenceReaderJob(Args _args)
    #{
    #    container result;
    #
    #    info('Calling OSIBase with batch job RecId:');
    #    result = OSISysRecurrenceReader::getBatchInfoByRecId(5637218082);
    #    if (OSISysRecurrenceReader::getBatchInfo_GetStatus(result) == 'Batch Job Found')
    #    {
    #        info(strFmt('  Log level                          : %1', OSISysRecurrenceReader::getBatchInfo_LogLevel(result)));
    #        info(strFmt('  Caption                            : %1', OSISysRecurrenceReader::getBatchInfo_Caption(result)));
    #        info(strFmt('  Runtime job                        : %1', OSISysRecurrenceReader::getBatchInfo_RuntimeJob(result)));
    #        info(strFmt('  Original start date time           : %1', OSISysRecurrenceReader::getBatchInfo_OrigStartDateTime(result)));
    #        info(strFmt('  Original start date                : %1', OSISysRecurrenceReader::getBatchInfo_OrigStartDate(result)));
    #        info(strFmt('  Original start time                : %1', OSISysRecurrenceReader::getBatchInfo_OrigStartTime(result)));
    #        info(strFmt('  Next start date time               : %1', OSISysRecurrenceReader::getBatchInfo_NextStartDateTime(result)));
    #        info(strFmt('  Next start date                    : %1', OSISysRecurrenceReader::getBatchInfo_NextStartDate(result)));
    #        info(strFmt('  Next start time                    : %1', OSISysRecurrenceReader::getBatchInfo_NextStartTime(result)));
    #        info(strFmt('  Time zone                          : %1', OSISysRecurrenceReader::getBatchInfo_TimeZone(result)));
    #        info(strFmt('  Recurrence type                    : %1', OSISysRecurrenceReader::getBatchInfo_RecurrenceEnd(result)));
    #        info(strFmt('  Recurrence                         : %1', OSISysRecurrenceReader::getBatchInfo_Recurrence(result)));
    #    }
    #    else
    #    {
    #        info(OSISysRecurrenceReader::getBatchInfo_GetStatus(result));
    #    }
    #
    #    info('');
    #    info('Calling OSIBase with batch job Caption:');
    #    result = OSISysRecurrenceReader::getBatchInfoByCaption('KW Test');
    #    if (OSISysRecurrenceReader::getBatchInfo_GetStatus(result) == 'Batch Job Found')
    #    {
    #        info(strFmt('  Log level                          : %1', OSISysRecurrenceReader::getBatchInfo_LogLevel(result)));
    #        info(strFmt('  Caption                            : %1', OSISysRecurrenceReader::getBatchInfo_Caption(result)));
    #        info(strFmt('  Runtime job                        : %1', OSISysRecurrenceReader::getBatchInfo_RuntimeJob(result)));
    #        info(strFmt('  Original start date time           : %1', OSISysRecurrenceReader::getBatchInfo_OrigStartDateTime(result)));
    #        info(strFmt('  Original start date                : %1', OSISysRecurrenceReader::getBatchInfo_OrigStartDate(result)));
    #        info(strFmt('  Original start time                : %1', OSISysRecurrenceReader::getBatchInfo_OrigStartTime(result)));
    #        info(strFmt('  Next start date time               : %1', OSISysRecurrenceReader::getBatchInfo_NextStartDateTime(result)));
    #        info(strFmt('  Next start date                    : %1', OSISysRecurrenceReader::getBatchInfo_NextStartDate(result)));
    #        info(strFmt('  Next start time                    : %1', OSISysRecurrenceReader::getBatchInfo_NextStartTime(result)));
    #        info(strFmt('  Time zone                          : %1', OSISysRecurrenceReader::getBatchInfo_TimeZone(result)));
    #        info(strFmt('  Recurrence type                    : %1', OSISysRecurrenceReader::getBatchInfo_RecurrenceEnd(result)));
    #        info(strFmt('  Recurrence                         : %1', OSISysRecurrenceReader::getBatchInfo_Recurrence(result)));
    #    }
    #    else
    #    {
    #        info(OSISysRecurrenceReader::getBatchInfo_GetStatus(result));
    #    }
    #
    #}
  ENDSOURCE
  PROPERTIES
    Origin              #{DE838A0F-C720-4DD5-9CCC-2C3809910FF9}
  ENDPROPERTIES
 

***Element: END

---- End Code ----

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,130 Super User 2025 Season 2 on at

    Hi Kurt,

    What is your question here?

  • Kurt Warner Profile Picture
    157 on at

    No question, I had searched and found no information specifically defining SysRecurrenceData and how to parse it. Posting my findings here to help others.

  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    Sharing your findings is a great idea, if you don't want to discuss anything, the discussion forum isn't the best place. You can have a blog here as Dynamics Community, which you can use for things like that. Please consult Request a New Blog or Blog to Syndicate.

    Also, just pasting some code without any explanation isn't very useful. Please describe the code next time in your blog posts or when you're asking a question or suggesting a solution in a forum.

    And try to provide code in a form that allows others to use it. Because you've pasted the content of an .xpo file here, you seem to expect people to copy it, paste it to a new .xpo file and import it to their AX 2012 environment. But they can't get exactly what you had, because you've pasted your code as normal text instead of using the </> button in the rich formatting view and therefore each line of your code is now wrapped in a paragraph in HTML. Probably the best approach would be pasting code in a readable form (not an .xpo) and providing an .xpo file as attachment.

  • DiegoAraujo Profile Picture
    35 on at

    Useful class!

    thx!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans