Options

NAV Test Framework / Open/Close Sales Statistics from Sales Quotes

MACL2MACL2 Member Posts: 10
Hi,

I Need to write a patch that does the following:

Loop through all the sales quotes. For each sales Quote the sales statistics Action has to be launched (there is some code on page 160 that is executed). Then just Close sales statistics page again and proceed to the next sales Quote.

To do it the traditional way I could write a Report/codeunit that Loops through the sales quotes. Since I cannot have any GUI interaction (page 160 opens when I launch the action Sales statistics) I would copy the code from page 160 and integrate it into my Report/codeunit.

So I thought of another Approach. Why not use the test Framework that NAV provides where I can handle UI interactions. I wrote a simple test codeunit und tried to achieve the above mentioned Goal. Here is the code:

OBJECT Codeunit 99992 Test: Open Statistics Page
{
OBJECT-PROPERTIES
{
Date=15.11.17;
Time=11:50:22;
Modified=Yes;
Version List=;
}
PROPERTIES
{
Subtype=Test;
OnRun=BEGIN
END;

}
CODE
{
VAR
SalesHeader@1000000000 : Record 36;
SalesStatistics@1000000002 : TestPage 160;
SalesQuotes@1000000003 : TestPage 9300;

[Test]
[HandlerFunctions(SalesStatisticsPageHandler)]
PROCEDURE MyTestFunction@1000000001();
BEGIN
// Quotes
SalesHeader.SETRANGE("Document Type", SalesHeader."Document Type"::Quote);
SalesQuotes.OPENEDIT;
IF SalesHeader.FINDSET THEN REPEAT
SalesQuotes.GOTORECORD(SalesHeader);
SalesStatistics.TRAP;
SalesQuotes.Statistics.INVOKE;
UNTIL SalesHeader.NEXT = 0;
SalesQuotes.CLOSE;
END;

[ModalPageHandler]
LOCAL PROCEDURE SalesStatisticsPageHandler@1000000000(VAR SalesStatistics@1000000000 : TestPage 160);
BEGIN
SalesStatistics.OK.INVOKE;
END;

BEGIN
END.
}
}

This is actually the first time I am using the test Framework. My Problem is that page 160 (sales statistics) is opened physically instead of using the ModalPageHandler I have provided. Somewhere I am missing something.

One more thing: In my case the test function should of course commit the changes to the database! Some VAT relevant fields are updated.

It would be great if someone could help me to get the above code to work.

Best regards,
MACL2
Sign In or Register to comment.