RESET Function

satish_navsatish_nav Member Posts: 65
TestCount := TestRecord.COUNT; //Result TestCount=5;

TestRecord.SETRANGE(TestRecord.ItemNo,TestRecord.ItemNo);
TestCount := TestRecord.COUNT; //Result TestCount=2;
TestRecord.DELETEALL;
TestCount := TestRecord.COUNT; //Result TestCount=0;
TestRecord.RESET;
TestCount := TestRecord.COUNT; //Result TestCount=5;

But when i RESET the record variable then the total records in the TestRecor showing 5 Instead of 3.


Can u help me out Plzzzz.
Thanks in advance..

Satish...

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    TestRecord.SETRANGE(TestRecord.ItemNo,TestRecord.ItemNo);
    TestCount := TestRecord.COUNT; //Result TestCount=2;

    TestRecord.RESET;
    TestRecord.DELETEALL;
    TestCount := TestRecord.COUNT; //Result TestCount=0;
    TestRecord.RESET;
    TestCount := TestRecord.COUNT; //Result TestCount=5;

    ----
    Deleteall only deletes all in the filter.
  • satish_navsatish_nav Member Posts: 65
    Mark,

    Here i want to add the Qty from each record based on ItemNo. and for that i applied SETRANGE with Item Number and i got 2 records. Now i added the qty and then delete the resulted reords and now i reset the record variable for remaining 3 records. But when i reset,
    here showing total 5 records as early. Even i used COMMIT also after DELETEALL function.
    Thanks in advance..

    Satish...
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Use client monitor to see what happens. I think if you look at the SQL Statements you'll understand.

    Also, deleting data like this in a transaction is extremely dangerous and absolutely not best practice. You should reconsider your design.

    What is it you are trying to achieve?
  • kapamaroukapamarou Member Posts: 1,152
    satish_nav wrote:
    TestCount := TestRecord.COUNT; //Result TestCount=5;

    TestRecord.SETRANGE(TestRecord.ItemNo,TestRecord.ItemNo);
    TestCount := TestRecord.COUNT; //Result TestCount=2;
    TestRecord.DELETEALL;
    TestCount := TestRecord.COUNT; //Result TestCount=0;
    TestRecord.RESET;
    TestCount := TestRecord.COUNT; //Result TestCount=5;


    Have you used RESET before all this code?
    Could your record variable have already filters before this code is reached?
  • satish_navsatish_nav Member Posts: 65
    No, I have not used any filters before, on the record variable.
    In my table i have records having Item Number and Vendor Number. Based on the vendor Number i want to Create the Quote. If the Item Is repeated for the same Vendor the Qty Should add.

    Vend Item Qty
    V1 Item1 1
    V1 Item1 2
    V2 Item2 1
    V2 Item2 2
    V1 Item3 1

    I want to Create Purch Quote Like this

    Purch.Quote 1
    V1
    Item1 3
    Item3 1

    Purch.Quote 2 ---> V2
    Item2 3

    I applied only fiter with Item No, and did totalQty count from resulting records and now creaed Purchase Line with that item and the Qty is TotalQty...Now i dont want this resultant records any more so i deleted resultant records with RecVariable.DeleteAll then now i want the remaining records so for that i used RecVariable.RESET, but after this line executed
    now getting the all records in this RecVariable including Deleted Records.



    Can any body share your experience..
    Thanks in advance..

    Satish...
  • fverkelfverkel Member Posts: 66
    Well .... this seems just not possible. So it teases my brain. :?

    1.
    Are you absolutely sure that there are no filters from the beginning?
    Markedonly?
    Maybe you are overlooking filters in different filtergroups? RESET resets all filters in all filtergroups, and also special filters like MARKEDONLY. It also resets the currentkey to the primary key.
    You could do a count from start to make sure.

    2.
    Your code says DELETEALL. Are you sure that is it not DELETEALL(TRUE)?
    In that case code in the OnDelete trigger could cause problems.

    3.
    The value of TestCount: do you get this value from the debugger?
    The debugger might be wrong.

    4.
    Are you using a dataport? And are you using the trial run (Ctrl+R)?
    I believe that Navision doesn't make modifications then.

    5.
    Maybe you've overlooked something.
    Typing mismatches? Are there more recordvariables with similar names?
    Code inbetween the code that you posted, which might change filters? Function calls?
    Is this code spread over several triggers of functions? In that case: is it a local variable?
    Is there also a global variable with the same name?

    OK, now I am curious what the problem is or was. Please let me know and set this issue to 'Solved'.
    Keep It Simple and Stupid (KISS), but never oversimplify.
Sign In or Register to comment.