-->

Fetch Method Not Picking Up First Value On Report

2019-08-09 14:33发布

问题:

me again with another report query... I've come across this before and resolved the issue, but having checked the existing report I cannot see where I am going wrong, so hopefully someone else looking at this will be able to help...

Basically, I have a report like any other, with two headers and a body section, and some static fields as programmable sections. The headers and programmable sections are fine and run as expected. The data within the body section comes from fields within the ProdBOM table, and there is a relationship between this table and the main table I am using as my datasource. Both of these are datasources in my report.

I have input the following code into the fetch method;

public boolean fetch()
{
    ProdBom                 _prodBom;
    LogisticsControlTable   _logisticsControlTable;
    ;

    queryRun = new QueryRun(this);

    if (!queryRun.prompt() || !element.prompt())
    {
        return false;
    }

    while (queryRun.next())
    {
        if (queryRun.changed(tableNum(LogisticsControlTable)))
        {
            _logisticsControlTable = queryRun.get(tableNum(LogisticsControlTable));
            if(_logisticsControlTable)
            {
                element.newPage();
            }
            this.send(_logisticsControlTable);

            if(_logisticsControlTable.ProdId)
            {
                while select _prodBom where _prodBom.ProdId == _logisticsControlTable.ProdId
                {
                    element.send(_prodBom);
                }
            }
        }
    }
    return true;
}

The result is that the first page's body section has no data, but the following pages have data in the body, is there any reason why this is happening?

回答1:

You explicitly calls element.newPage() before the first send, which creates a blank page.

A control variable will do the trick:

boolean newPage = false;    
...    
if (newPage)
    element.newPage();
else
    newPage = true;


回答2:

QueryRun.Changed():

Determines whether the specified data source has fetched a new value since the last call to the QueryRun.next method.

Is your IF clause causing the first pass to skip?

Or alternatively, is it because you call "element.newPage()" right away? Is there an existing page when the report is created that you should first fill with data before creating a new page?

I'm weaker with reporting in AX if you can't tell.



回答3:

thank you for your assistance. It was partially down to the newPage() function. To resolve this issue I added a clause to the IF as Jan suggested, so that a new page is only printed when the loop picks up a new uniqueID. I also had to replace the ProductionBom section as a programmable so that it was picked up in the first pass, finally ammending the while select statement as follows;

while select _prodBom where _prodBom.ProdId == _logisticsControlTable.ProdId
{
    if(_logisticsControlTable.ProdId == _prodBom.ProdId)
    {
        element.send(_prodBom);
    }
    element.execute(1);
}


回答4:

//Started with Classdeclaration
Boolean = newpage;

/*Second step would be your after debugging it depends on your
  report/design which method is going to call. Mine was Fetch.
  So, take a look.*/

newpage = true,

/*Third step would be execution part; there you just need to put
  'if' condition.*/

If(newpage==false)
{
    element.newpage();
}
else
{
  newpage=false;
}

There you go, first called the function followed by element.newpage and so on.