Why inserting from a report do not work?

ImaspalImaspal Member Posts: 68
Hi Experts!

I'm trying to insert a record to the table from a report, but this doesn't work. My table is empty after I'm using the INSERT-function in my report's OnPreReport - Trigger.

Can you help me with this, what is wrong?

Yours,
Imaspal

Comments

  • tinoruijstinoruijs Member Posts: 1,226
    Can you give the complete code you wrote?

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • garakgarak Member Posts: 3,263
    popps up an error:?:

    your Table variable is not temporary :?: You make YourtableVariable.insert() :?: Lets see the source

    Regards
    Do you make it right, it works too!
  • ImaspalImaspal Member Posts: 68
    There is no error, after running following code the table tmpSalesPersonPurchaser is empty.

    I'm not using a temporary table-variable, is this the problem?

    My sourcecode looks like this:
    tmpSalesPersonPurchaser.INIT;
    SalespersonPurchaser.RESET;
    IF SalespersonPurchaser.FINDSET THEN
      REPEAT
        tmpSalesPersonPurchaser.Code := SalespersonPurchaser.Code;
        tmpSalesPersonPurchaser.Name := SalespersonPurchaser.Name;
        tmpSalesPersonPurchaser.Code2 := SalespersonPurchaser.Code;
        tmpSalesPersonPurchaser.INSERT;
      UNTIL SalespersonPurchaser.NEXT = 0;
    
    tmpSalesPersonPurchaser.Code := FORMAT(CURRENTDATETIME,0,'<Day,2><Hours24><Minutes,2>');
    tmpSalesPersonPurchaser.Name := Text002;
    tmpSalesPersonPurchaser.Code2 := '';
    tmpSalesPersonPurchaser.INSERT;
    
  • garakgarak Member Posts: 3,263
    tmpSalesPersonPurchaser and SalespersonPurchaser on the same table (13) :?: tmpSalesPersonPurchaser is temporary or (Proper< of variable)
    Do you make it right, it works too!
  • awarnawarn Member Posts: 261
    Maybe you should be in the OnAfterGetRecord, not the OnPreReport (this trigger happens before any of the sections are read). Or maybe you are intentionally purring it there, but without the code to see we cannot know...

    -a
  • ImaspalImaspal Member Posts: 68
    garak wrote:
    tmpSalesPersonPurchaser and SalespersonPurchaser on the same table (13) :?: tmpSalesPersonPurchaser is temporary or (Proper< of variable)

    In this case tmpSalesPersonPurchaser and SalespersonPurchaser are different tables.

    Yours,
    Imaspal
  • garakgarak Member Posts: 3,263
    it must work. the code is correct. The OnPreReport Trigger can also be used.
    Do you have checked if SalesPersons are exist or do you have started the debugger to see what navision is doing :?:

    regards
    Do you make it right, it works too!
  • ImaspalImaspal Member Posts: 68
    garak wrote:
    it must work. the code is correct. The OnPreReport Trigger can also be used.
    Do you have checked if SalesPersons are exist or do you have started the debugger to see what navision is doing :?:

    There are Salespersons on table 13.

    I tried to run this same code with codeunit and it worked. When I tried to run this codeunit from my report's OnPreReport trigger => this did not work. The table was empty the same way as it was, when tried to run this code straight from my report.

    I haven't tried the debugger yet..I let you know, if I find the problem with debugger.

    Yours,
    IP
  • BeliasBelias Member Posts: 2,998
    you have
    "tmpSalesPersonPurchaser" variable
    I suppose that tmp prefix means that this variable is temporary...
    you won't find records inserted if you insert them in a temporary variable...
    did you check if the variable is temporary (as garak suggest)?
    8)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • ImaspalImaspal Member Posts: 68
    Belias wrote:
    you have
    "tmpSalesPersonPurchaser" variable
    I suppose that tmp prefix means that this variable is temporary...
    you won't find records inserted if you insert them in a temporary variable...
    did you check if the variable is temporary (as garak suggest)?
    8)

    Yes I checked it. The variable is not temporary.

    Yours,
    IP
  • BeliasBelias Member Posts: 2,998
    haven't you got 2 variables with the same name?one local and one global?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • ImaspalImaspal Member Posts: 68
    Belias wrote:
    haven't you got 2 variables with the same name?one local and one global?

    Both variables are Globals.

    Yours,
    IP
  • BeliasBelias Member Posts: 2,998
    sorry, maybe I didn't explain well.
    i mean: have you got "tmpSalesPersonPurchaser" in globals and another "tmpSalesPersonPurchaser" in the locals(of the trigger/function where your code is)?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • awarnawarn Member Posts: 261
    You should run the debugger and see if it hits your code at all.

    Otherwise try the below. Using CONFIRM as opposed to message pauses the code so you know exactly where youa re...

    if not confirm(format(tmpSalesPersonPurchaser.count)) then
    error('');
    tmpSalesPersonPurchaser.INIT;
    SalespersonPurchaser.RESET;
    IF SalespersonPurchaser.FINDSET THEN
    REPEAT
    tmpSalesPersonPurchaser.Code := SalespersonPurchaser.Code;
    tmpSalesPersonPurchaser.Name := SalespersonPurchaser.Name;
    tmpSalesPersonPurchaser.Code2 := SalespersonPurchaser.Code;
    tmpSalesPersonPurchaser.INSERT;
    UNTIL SalespersonPurchaser.NEXT = 0;

    if not confirm(format(tmpSalesPersonPurchaser.count)) then
    error('');

    tmpSalesPersonPurchaser.Code := FORMAT(CURRENTDATETIME,0,'<Day,2><Hours24><Minutes,2>');
    tmpSalesPersonPurchaser.Name := Text002;
    tmpSalesPersonPurchaser.Code2 := '';
    tmpSalesPersonPurchaser.INSERT;

    if not confirm(format(tmpSalesPersonPurchaser.count)) then
    error('');
  • ImaspalImaspal Member Posts: 68
    Belias wrote:
    sorry, maybe I didn't explain well.
    i mean: have you got "tmpSalesPersonPurchaser" in globals and another "tmpSalesPersonPurchaser" in the locals(of the trigger/function where your code is)?

    No, there is only a global variable "tmpSalesPersonPurchaser"´in trigger OnPreReport

    Yours,
    IP
  • garakgarak Member Posts: 3,263
    so, whats the result from debugging?
    Do you make it right, it works too!
  • ImaspalImaspal Member Posts: 68
    The debugger seems to hit my code.

    Yours,
    IP
  • awarnawarn Member Posts: 261
    Is there an error later in the report? If there is an error then the insertions will be rolled back.

    What is the table number of both the variables:
    SalespersonPurchaser
    tmpSalesPersonPurchaser

    I would like to see the results of putting in the COUNTS in the code to see if anything is inserted.
  • XypherXypher Member Posts: 297
    If I had to guess it is because you have INIT and then RESET proceeding after it. (Yes I am aware the two calls are being made to two separate variables. But they are the same table no?)
Sign In or Register to comment.