Why my code doesn't modify all records?

sjensjen Posts: 32Member
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 Posts: 276
    edited 2019-07-11 Accepted 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, but use forum instead, perhaps other people have the same question, or better answers.

Answers

  • SanderDkSanderDk Posts: 276Member
    edited 2019-07-11 Accepted 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, but use forum instead, perhaps other people have the same question, or better answers.
  • DuikmeesterDuikmeester Hoorn, The NetherlandsPosts: 296Member
    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 Posts: 32Member
    Thank you all!
  • RockWithNAVRockWithNAV Posts: 872Member
    @sjen Keeping performance in mind I will recommend MODIFYALLL.
Sign In or Register to comment.