How can FINDSET fail after NOT ISEMPTY

ChaosDChaosD Member Posts: 4
I've been seeing a very weird issue in our BC14 CU19 code where the following fails:
[...]
IF NOT ItemAnalysisView2.ISEMPTY THEN BEGIN
  ItemAnalysisView2.LOCKTABLE;
  ItemAnalysisView2.FINDSET(TRUE, TRUE); 
  [...]
END;

ItemAnalysisView2.FINDSET(TRUE, TRUE); fails with the error that no record has been found within the filter.
How is this possible immediately after ISEMPTY returned FALSE, which means there should be a record in the table? The filter doesn't change between both lines.
Could it have something to do with the .LOCKTABLE line when FINDSET(TRUE) is also implicitly calling LOCKTABLE on that record?

The full code is a modified version of the UpdateAll() function in Codeunit 7150:
ItemAnalysisView2.SETRANGE(Blocked, FALSE);
IF DirectlyFromPosting THEN
  ItemAnalysisView2.SETRANGE("Update on Posting", TRUE);

IF ItemAnalysisView2.ISEMPTY THEN
  EXIT;

InitLastEntryNo;

IF DirectlyFromPosting THEN BEGIN
  ItemAnalysisView2.SETFILTER("Last Entry No.", '<%1', LastValueEntryNo);
  IF ItemAnalysisView2.ISEMPTY THEN BEGIN
    ItemAnalysisView2.SETRANGE("Last Entry No.");
    ItemAnalysisView2.SETFILTER("Last Service Entry No.", '<%1', LastServLedgEntryNoG);
  END;
END;

IF NOT ItemAnalysisView2.ISEMPTY THEN BEGIN
  ItemAnalysisView2.LOCKTABLE;
  ItemAnalysisView2.FINDSET(TRUE, TRUE);
  REPEAT
    UpdateOne(ItemAnalysisView2, Which, ItemAnalysisView2."Last Entry No." < LastValueEntryNo - 1000);
  UNTIL ItemAnalysisView2.NEXT = 0;
END;

Answers

  • aceXaceX Member Posts: 166
    Why do you call UpdateKey parameter in FINDSET? This option parameter will be removed in future releases in Business Central. Try with:

    ItemAnalysysView2.FINDSET(TRUE)

    I'm not sure that this is the problem, but for now I have just that idea... let's try :smile:
  • vaprogvaprog Member Posts: 1,140
    Please make sure your SQL database checks Ok.

    If it does, and the issue is repeatable, this is a case for Microsoft support.
    If the issue is not repeatable, then most likely you have a race condition:
    You: ISEMPTY
    He: DELETE
    You: FINDSET
    

    As a workaround just delete the
    IF NOT ItemAnalysisView2.ISEMPTY
    
Sign In or Register to comment.