Update a field when a value in another field is validated

Hello,

Why the following code is not updating the value of "No. Contrat" when a new value of "Code Client" is seleted (this code is in a Card page)
                field("Code Client"; "Code Client")
                {
                    CaptionML = FRB = 'Code client';  
                    trigger OnValidate();
                    var
                        locContrat : Record Contrat;
                        locContratDetail : Record "Contrat Detail";
                    begin 
                        locContrat.Reset;
                        locContrat.SetRange("Code Client","Code Client");
                        locContrat.SetCurrentKey("No.");
                        if locContrat.FindLast
                            then Validate("No. Contrat",locContrat."No.");
                        Message ('%1 : Contrat No = %2',locContrat.FindLast,locContrat."No."); // show "YES" and the correct value of "No. Contrat"
                        CurrPage.Update(true);
                    end;                                  
                }

Best Answer

Answers

  • AlexeyShaminAlexeyShamin Member Posts: 80
    Hello!

    try to move code to onValidate trigger in table
  • MelekBoujelbeneMelekBoujelbene Member Posts: 17
    edited 2020-09-22
    Hello AlexeyShamin,

    Thank you for your quick reply.
    It didn't change anything.
    (sorry i didn't know your answer will be colored in red :/ )
  • AlexeyShaminAlexeyShamin Member Posts: 80
    ok. try to change
    Validate("No. Contrat",locContrat."No."); --> "No. Contrat" := locContrat."No.";

    If it will be ok - error in inValidate trigger on field "No. Contrat"
  • MelekBoujelbeneMelekBoujelbene Member Posts: 17
    Unfortunately that gave the same result :/
  • lubostlubost Member Posts: 628
    locContrat.modify; missing
  • AlexeyShaminAlexeyShamin Member Posts: 80
    Add before message line:
    Message ('%1',"No. Contrat");

    Or use Debuger to evaluate value of Rec."No. Contrat" after VALIDATE
Sign In or Register to comment.