Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

Query in Report (2009) keep previous query value

Posted on by 157

Hello Everyone

I want to print a report (2009) [NOT SSRS from a button that I have in a form. 

I create a new button which have my main table as a datasource and after that I overide the init method 

public void init()
{


     MyTable myTable;

     ;

     super();

     myTable = element.args().record();

     this.query().dataSourceTable(tablenum(MyTable)).addRange(fieldnum(MyTable, Field_1)).value(myTable.Field_1);

}

When I debuged it, it seems like to take the correct value from the query but always in the dialog it returns an old one  Field_1 value, which now does not even exist in my records. 

I read that a method parmLoadFromSysLastValue(false) can do what I am trying to do here but it seems that is not in this or query methods. 

Does anyone know how I can pass this issue?

  • SGbron Profile Picture
    SGbron 157 on at
    RE: Query in Report (2009) keep previous query value

    Thank you both for the help.

    The solution was to create a new method in the report named mustLoadSaveQuery()

    as below

        public boolean mustLoadSaveQuery()

        {

              return false;

        }

    That solves the issue.

  • Martin Dráb Profile Picture
    Martin Dráb 225,549 Super User on at
    RE: Query in Report (2009) keep previous query value

    I don't really remember MorphX reports anymore, but it indeed sounds like that you add a range before the previously-used query is loaded from SysLastValue (and therefore your code has no effect).

    Therefore you have two options. Either prevent loading from SysLastValue, or let it load and change query ranges afterwards.

    You can use the debugger to find out where the loading happens and which conditions are used there. I would start by checking if it happens in super() of dialog().

  • SGbron Profile Picture
    SGbron 157 on at
    RE: Query in Report (2009) keep previous query value

    Hello Gunjan

    Thank you for your reply.

    Yes, I also had tried this one but I had the same issue.

    I just found what cause this problem.

    It was the usage data. I cleared everything and took the correct one. 

    But everytime I have to clear the usage data.... and that is not optimal...

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: Query in Report (2009) keep previous query value

    Hi,

    Have you tried using findOrCreateQuery()? Maybe something like this -

    SysQuery::findOrCreateRange(this.query().dataSourceTable(tablenum(MyTable)), fieldNum(MyTable, Field_1)).value(queryValue(myTable.Field_1));

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans