Why my code doesn't modify all records?

sjensjen Member Posts: 53
Hello,
I am writing a report and my code doesn't modify all records. It is so strange. What am I missing? I don't want to use modifyall,
When I look at my Res. Ledger Entry table I can see same resource number records but some of them have Unit of Measure Code value and some don't. They all suppose to have after I run my report.

Thank you

Resource - OnAfterGetRecord()

    ResLedgerEntry.SETRANGE("Resource No.", "No.");
    IF ResLedgerEntry.FINDSET THEN BEGIN
       ResLedgerEntry."Unit of Measure Code" := "Base Unit of Measure";
       ResLedgerEntry.MODIFY;
    END;

Best Answer

  • SanderDkSanderDk Member Posts: 502
    edited 2019-07-11 Answer ✓
    You are only modifying the first record you, need to add a repeat/until
    ResLedgerEntry.SETRANGE("Resource No.", "No.");
        IF ResLedgerEntry.FINDSET(TRUE,FALSE) THEN
           REPEAT
                ResLedgerEntry."Unit of Measure Code" := "Base Unit of Measure";
                ResLedgerEntry.MODIFY;
           UNTIL ResLedgerEntry.NEXT = 0;
        END;
    
    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.

Answers

  • SanderDkSanderDk Member Posts: 502
    edited 2019-07-11 Answer ✓
    You are only modifying the first record you, need to add a repeat/until
    ResLedgerEntry.SETRANGE("Resource No.", "No.");
        IF ResLedgerEntry.FINDSET(TRUE,FALSE) THEN
           REPEAT
                ResLedgerEntry."Unit of Measure Code" := "Base Unit of Measure";
                ResLedgerEntry.MODIFY;
           UNTIL ResLedgerEntry.NEXT = 0;
        END;
    
    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
  • DuikmeesterDuikmeester Member Posts: 307
    If there is no need for triggering field logic you could use:
    ResLedgerEntry.SETRANGE("Resource No.","No.");
    ResLedgerEntry.MODIFYALL("Unit of Measure Code","Base Unit of Measure");
    
  • sjensjen Member Posts: 53
    Thank you all!
  • RockWithNAVRockWithNAV Member Posts: 1,139
    @sjen Keeping performance in mind I will recommend MODIFYALLL.
Sign In or Register to comment.