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)

Report in batch, date dialog

(0) ShareShare
ReportReport
Posted on by

 


Hello,

I have a report that pulls a date from a dialog box.

When I schedule a batch for this report (say every week night), the date
always stays the same as when you scheduled it. I want to initialize the
date every night with the current date (today()). I've tried to initialize
the date in the getFromDialog, fetch, init and other methods of the report
but it seems like these methods are not being called when the batch is ran.
Here is what I've tried:

public boolean fetch()
{
SysReportRun sysReportRun;
;

sysReportRun = this;
if (sysReportRun.isBatchMode())
{
runDate = today();
}
}

public void init()
{
;
runDate = today();
super();

}

etc etc.

I've also used infolog messages in these methods so I can see if the batch
is actually calling the methods but when I look at the info on the batch,
there is nothing in there.

Is there some property or something else that I am missing in order to get
this to work properly? I have other reports that are similar that work fine
in batch mode but I am not able to see any difference. (both are scheduled
to run on server etc etc).

Any assistance would be appreciated.

Thanks.
 

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    The value is (very likely) packed and saved to the database. The batch process load it and use it for records filtering or something.

    If the report is never used without a value in runDate, you can fill the value with current date (after unpacking, for example in the run() method) if it is empty. If empty runDate is acceptable, you need an additional variable to distinguish "all dates" and "current date" meaning.

    Another approach could be to use query and fill "(currentSessionDate())" as a range value, but it is not applicable in all cases.

  • Community Member Profile Picture
    on at

     Hi Martin,

     Thank you for the reply.  I have already tried to add the range value in the run method but still have no success:

     public void run()
    {
        ;

        this.query().dataSourceTable(tableNum(CustInvoiceJour)).addRange(FieldNum(CustInvoiceJour, InvoiceDate));
         this.query().dataSourceTable(tableNum(CustInvoiceJour)).findRange(fieldNum(CustInvoiceJour, InvoiceDate)).value(strFmt("%1", today()));


        super();
    }

    Your advice to use currentSessionDate()...  Can you give me an example?  It is worth trying.  Thank you very much.

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

    I don't understand if your application logic uses a member variable (runDate in your first example) or a query. That is big difference.

    About currentSessionDate(): AX2009 contains the class named SysQueryRangeUtil. Methods defined in that class can be used directly in the query ranges (when you are defining your batch process). Unlike direct query range values, methods from SysQueryRangeUtil must be enclosed in additional parentheses. See an example:

    SysQueryRangeUtil example 

  • Community Member Profile Picture
    on at

     Martin,

    My report is based off of query built using AOT.  The 'dialog' method is overriden to add a variable runDate to specify which date to apply to the query (my query range).  In the run() method, it was originally coded to pass in the range: 

    this.query().dataSourceTable(tableNum(CustInvoiceJour)).findRange(fieldNum(CustInvoiceJour, InvoiceDate)).value(strFmt("%1", runDate));

     But I can't seem to get it to only pass in todays date and not the saved (packed) date when you first schedule the batch.  Does this clarify?

     Thanks again for all the help.

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

    OK, so you can easily set it as a field range in RunBase dialog and you don't need to play with class variables. :-)

    I didn't try it but I'm not sure if ("%1", runDate) creates a correct range value. The standard implentation (in SysQuery::value()) is different.

    Check if the resulting query is really what you want (call this.query().dataSourceNo(1).toString() to get text a represenation of the query).

    The issue could be also in using of today() in the impersonated batch job.

    Or there is some additional date-based logic somethere in that class…

  • Community Member Profile Picture
    on at

     I used your output statement  info(strfmt("%1", this.query().dataSourceNo(1).toString())); and I get back (in short):

     

    SELECT * FROM ...

    JOIN * FROM CustInvoiceJour WHERE CustTable.AccountNum = CustInvoiceJour.InvoiceAccount AND ((InvoiceDate = {ts '2010-06-03 00:00:00.000'})) JOIN * FROM CustInvoiceTrans WHERE CustInvoiceJour.InvoiceDate = CustInvoiceTrans.InvoiceDate AND CustInvoiceJour.InvoiceId = CustInvoiceTrans.InvoiceId

     

     Is the InvoiceDate = {ts '2010-06-03 00:00:00.000'} part causing errors?

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

    It depends on what you expect. If the entire query is correct ({ts '2010-06-03 00:00:00.000'} is absolutely valid range value), but behavior of the application is not… the problem probably isn't in the query.

  • Community Member Profile Picture
    on at

    Hi Martin,

    I agree.  There is nothing wrong with the query.  It is an issue of what is being saved from the last reportRun.  This one is frustrating.  I'll let you know if we come up with some sort of solution and hopefully find the root of this problem.

    Thanks for the help.

    Regards.

  • Suggested answer
    Mark Prouty Profile Picture
    1,312 on at

    initialize the date value in the dialog method, right after the dialog =super(_dialog); statement

    public Object dialog(Object _dialog)

    {;

      dialog =super(_dialog); statement

      toDate = systemDateGet() -7; // or use date functions from Global class ex: start of month, end of month etc

      dialogToDate        = dialog.addFieldValue(typeid(PeriodEnd), toDate, "@SYS14656");

      return dialog;

    }

  • Suggested answer
    Mark Prouty Profile Picture
    1,312 on at

    initialize the date value in the dialog method, right after the dialog =super(_dialog); statement

    public Object dialog(Object _dialog)

    {;

      dialog =super(_dialog); statement

      toDate = systemDateGet() -7; // or use date functions from Global class ex: start of month, end of month etc

      dialogToDate        = dialog.addFieldValue(typeid(PeriodEnd), toDate, "@SYS14656");

      return dialog;

    }

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans