Customized routine running

Developer101Developer101 Member Posts: 553
I have developed a NAV batch which updates some data in a table based on some calculations.

I ran the batch last time and I found out some updates were not done at all in the table and when I re-run it did updated.
I am now confused why it happend. I did not make any changes as the code looks fine to me , I just re-run it.



This routine updates thousands of entries but 2nd time it got it lucky not sure why not 1st time it did not work.

Any suggestions?
United Kingdom

Comments

  • geordiegeordie Member Posts: 655
    I think you should provide some additional details since the scenario is actually quite vague.
    Which tables did you update (std/custom)? Was your first run simultaneous with some users' posting transactions? How much time passed between 1st and 2nd run?
  • Developer101Developer101 Member Posts: 553
    OK I found the issue.

    The table is customized ledger entries.

    The problem is basically the loop at one piece of code wasn't working. The loop had 20 records to loop but it was doing just one time. the I removed SETCURRENTKEY code before filtration and it worked fine.

    Why is that I don't remember I faced this issue before.

    So my code was

    record.reset;
    record.setcurrentkey(field1,field2,field3);
    record.setrange(field1,value);
    record.setrange(field2,value);
    record.setrange(field3,value);
    if record.find('-') then
    repeat

    //do something
    record.modify

    until record.next = 0;
    end;

    the I commented setcurrentkey part of code and worked fine.

    Please help as I have lot of codes like that and I want to know what I am doing wrong here?

    thanks
    United Kingdom
  • Developer101Developer101 Member Posts: 553
    Can I please have suggestion on above?

    Thanks
    United Kingdom
  • BChatenetBChatenet Member Posts: 4
    Hi,

    Did you modify the value of Field1, 2 or 3 in your "do something" ?
  • MBergerMBerger Member Posts: 413
    You don't show WHAT you are modifying inside your loo, but i suspect you are changing the values you are filtering and/or sorting on, using the same record-variable as you are looping with. Make a second variable of the same recordtype, use that to GET the same record as the one you use in the loop and do your modifications on that.
    record1.reset;
    record1.setcurrentkey(field1,field2,field3);
    record1.setrange(field1,value);
    record1.setrange(field2,value);
    record1.setrange(field3,value);
    if record1.find('-') then
    repeat
      Record2.get(<primary key fields of the current selected record in record1>) ;
      //do something on record2
      Record2.modify ;
    until record1.next = 0;
    
  • Developer101Developer101 Member Posts: 553
    MBerger wrote:
    You don't show WHAT you are modifying inside your loo, but i suspect you are changing the values you are filtering and/or sorting on, using the same record-variable as you are looping with. Make a second variable of the same recordtype, use that to GET the same record as the one you use in the loop and do your modifications on that.

    Yes I was doing exactly that. Your code makes sense thanks.
    What makes me worried though is - this is my 7th year as NAV Developer : :roll:
    Does this happen to Experienced NAV developers, not knowing some basic things?
    United Kingdom
  • MBergerMBerger Member Posts: 413
    MBerger wrote:
    You don't show WHAT you are modifying inside your loo, but i suspect you are changing the values you are filtering and/or sorting on, using the same record-variable as you are looping with. Make a second variable of the same recordtype, use that to GET the same record as the one you use in the loop and do your modifications on that.

    Yes I was doing exactly that. Your code makes sense thanks.
    What makes me worried though is - this is my 7th year as NAV Developer : :roll:
    Does this happen to Experienced NAV developers, not knowing some basic things?
    Depends..if you have coded loops like this before, you COULD have stumbled upon this problem sooner. But there are cases where your code would work, just a lot less efficient.

    But even with my +/- 10 years of NAV coding experience, i have made the same mistake once or twice.....we are only human :)
  • Developer101Developer101 Member Posts: 553
    Depends..if you have coded loops like this before, you COULD have stumbled upon this problem sooner. But there are cases where your code would work, just a lot less efficient.

    But even with my +/- 10 years of NAV coding experience, i have made the same mistake once or twice.....we are only human :)[/quote]

    Thanks . Yes we are humans :)
    United Kingdom
Sign In or Register to comment.