Value from another table to a form

sarmigsarmig Member Posts: 89
Hi there,

I was just hired by a company and I'm supposed to work with Navision. Needless to say I'm a newbie with this software and, therefore, here I am asking for help.

The first thing I was asked to do is to make a value (from the field Run Time) from table 99000763 (I don't know if this is a default table from the software, or if it was created my our tech engineer) on form 50016, on a field I created...

What I did until now was creating the field on the form i want the value to show up and write this code in the OnValidate section of the field I created in the form (some names are in portuguese, never mind that):

RecRoutingHeader.RESET;
RecRoutingHeader.SETRANGE(RecRoutingHeader."No.","No. Macho");

IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN
RecRoutingHeader."No." := "No.";
RecRoutingHeader.Description := Description;
RecRoutingHeader.INSERT;
END;
"Routing No." := "No.";

RecRoutingLine.RESET;
RecRoutingLine.SETRANGE(RecRoutingLine."No.","Routing No.");
IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
RecRoutingLine."No." := "No.";
RecRoutingLine.Description := Description;
RecRoutingLine."Run Time" := "Run Time";
RecRoutingLine.INSERT;

END;

TempoEx := RecRoutingLine."Run Time";

Can you see what I'm trying to do here? We are a factory, I'm trying to import to the form the time it takes to fabricate certain product. That value is already in another table, but I want it to appear in the form as I fill it.

I know its kinda hard to explain the situation, and I appreciate any help you can give to a rookie like me. Even if you can't tell me specifically what I should do, at least give me some pointers. Thanks in advance!
«1

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Welcome to Mibuso and NAV :D
    in which fields OnValidate trigger you wrote this code?
  • sarmigsarmig Member Posts: 89
    I wrote it on the OnValidate trigger of the field I created on the form i want it to show up. I just want a value from another table to show up on the form as I fill it...
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    You should have written in TempoEx fields onvalidate as you have to show that field..
    it would be very helpful to you if you explain with names not as
    I wrote it on the OnValidate trigger of the field I created on the form i want it to show up. I just want a value from another table to show up on the form as I fill it...
  • sarmigsarmig Member Posts: 89
    You should have written in TempoEx fields onvalidate as you have to show that field..
    it would be very helpful to you if you explain with names not as
    I wrote it on the OnValidate trigger of the field I created on the form i want it to show up. I just want a value from another table to show up on the form as I fill it...

    TempoEx is a variable I created just to be the SourceExpr of that field. My intention was to make that value show up...
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Then in which trigger you wrote and what was the result?

    Onvalidate trigger will be called when user inputs some data in that field
  • sarmigsarmig Member Posts: 89
    Then in which trigger you wrote and what was the result?

    Onvalidate trigger will be called when user inputs some data in that field

    I wrote it on the OnValidate trigger of the TempoEx field (The field is actually called TempoExecução)

    I'll be uploading some images:

    Img1: I want to fill manually the field Nº OPL and No. Linha OP. Most of the field already fill themselves automatically, and I want the field "Tempo" to be filled too.

    Img2: As you can see, on the OnValidate trigger of the TempoExecução field, i have the code.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    This code vl be executed when you input value in TempoExecução field
    and when you have value in "No. Macho"
  • sarmigsarmig Member Posts: 89
    This code vl be executed when you input value in TempoExecução field
    and when you have value in "No. Macho"

    That's the thing. I don't want to input any value on TempoExecução. I want that field to be filled automatically with the value from the field Run Time from table 99000764.

    Where should I put the code? Under which trigger?
    How do I make the value of that field show up automatically?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Try it in placing Onopen form trigger and OnAftergetrecord trigger.
  • sarmigsarmig Member Posts: 89
    Try it in placing Onopen form trigger and OnAftergetrecord trigger.

    Nothing happened. Is something wrong with the code?

    Can I make it in a way that it gets the value after I input No. Linha OP?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Do you have value in "No. Macho"?

    Try it by placing its onvalidate and by giving the same input again or as u said.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    sarmig wrote:
    Try it in placing Onopen form trigger and OnAftergetrecord trigger.

    Nothing happened. Is something wrong with the code?

    I think so..

    can you copy the code and paste here without screenshot?..in
    your code here
    
  • sarmigsarmig Member Posts: 89
    sarmig wrote:
    Try it in placing Onopen form trigger and OnAftergetrecord trigger.

    Nothing happened. Is something wrong with the code?

    I think so..

    can you copy the code and paste here without screenshot?..in
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE(RecRoutingHeader."No.","No. Macho"); 
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
     RecRoutingHeader."No." := "No."; 
     RecRoutingHeader.Description := Description;
     RecRoutingHeader.INSERT;
    END;
    "Routing No." := "No.";
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE(RecRoutingLine."No.","Routing No.");
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
     RecRoutingLine."No." := "No.";
     RecRoutingLine.Description := Description;
     RecRoutingLine."Run Time" := "Run Time";
     RecRoutingLine.INSERT;
    
    END;
    
    TempoEx := RecRoutingLine."Run Time";
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    try this code
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
      RecRoutingHeader."No." := "No. Macho";
      RecRoutingHeader.Description := Description;
      RecRoutingHeader.INSERT;
    END;
    "Routing No." := "No.";
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.","Routing No.");
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
      RecRoutingLine"Routing No." := "Routing No.";
      RecRoutingLine.Description := Description;
      RecRoutingLine."Run Time" := "Run Time";
      RecRoutingLine.INSERT;
    END;
    
    TempoEx := RecRoutingLine."Run Time";
    
  • sarmigsarmig Member Posts: 89
    try this code
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
      RecRoutingHeader."No." := "No. Macho";
      RecRoutingHeader.Description := Description;
      RecRoutingHeader.INSERT;
    END;
    "Routing No." := "No.";
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.","Routing No.");
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
      RecRoutingLine"Routing No." := "Routing No.";
      RecRoutingLine.Description := Description;
      RecRoutingLine."Run Time" := "Run Time";
      RecRoutingLine.INSERT;
    END;
    
    TempoEx := RecRoutingLine."Run Time";
    

    Nothing happened...
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Where did you add this code?

    try adding messages in between the code and check like
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
      RecRoutingHeader."No." := "No. Macho";
      RecRoutingHeader.Description := Description;
      RecRoutingHeader.INSERT;
    END;
    RecRoutingHeader."Routing No." := "No."; // Modified this line again
    Message('%1',RecRoutingHeader."Routing No.");
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."Routing No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
      RecRoutingLine"Routing No." := "Routing No.";
      RecRoutingLine.Description := Description;
      RecRoutingLine."Run Time" := "Run Time";
      RecRoutingLine.INSERT;
    END;
    Message('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";
    
  • sarmigsarmig Member Posts: 89
    Where did you add this code?

    try adding messages in between the code and check like
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
      RecRoutingHeader."No." := "No. Macho";
      RecRoutingHeader.Description := Description;
      RecRoutingHeader.INSERT;
    END;
    RecRoutingHeader."Routing No." := "No."; // Modified this line again
    Message('%1',RecRoutingHeader."Routing No.");
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."Routing No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
      RecRoutingLine"Routing No." := "Routing No.";
      RecRoutingLine.Description := Description;
      RecRoutingLine."Run Time" := "Run Time";
      RecRoutingLine.INSERT;
    END;
    Message('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";
    


    It doesn't compile. Routing No. is not a field of any record variable. Its just a code variable. Do I need it?
  • sarmigsarmig Member Posts: 89
    sarmig wrote:
    Where did you add this code?

    try adding messages in between the code and check like
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
      RecRoutingHeader."No." := "No. Macho";
      RecRoutingHeader.Description := Description;
      RecRoutingHeader.INSERT;
    END;
    RecRoutingHeader."Routing No." := "No."; // Modified this line again
    Message('%1',RecRoutingHeader."Routing No.");
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."Routing No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
      RecRoutingLine"Routing No." := "Routing No.";
      RecRoutingLine.Description := Description;
      RecRoutingLine."Run Time" := "Run Time";
      RecRoutingLine.INSERT;
    END;
    Message('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";
    


    It doesn't compile. Routing No. is not a field of any record variable. Its just a code variable. Do I need it?

    My bad! It just does not exist in RecRoutingHeader. It exists in RecRoutingLine. Sorry...
  • sarmigsarmig Member Posts: 89
    sarmig wrote:
    sarmig wrote:
    Where did you add this code?

    try adding messages in between the code and check like
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
      RecRoutingHeader."No." := "No. Macho";
      RecRoutingHeader.Description := Description;
      RecRoutingHeader.INSERT;
    END;
    RecRoutingHeader."Routing No." := "No."; // Modified this line again
    Message('%1',RecRoutingHeader."Routing No.");
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."Routing No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
      RecRoutingLine"Routing No." := "Routing No.";
      RecRoutingLine.Description := Description;
      RecRoutingLine."Run Time" := "Run Time";
      RecRoutingLine.INSERT;
    END;
    Message('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";
    


    It doesn't compile. Routing No. is not a field of any record variable. Its just a code variable. Do I need it?

    My bad! It just does not exist in RecRoutingHeader. It exists in RecRoutingLine. Sorry...

    I tried using the code on the No. Linha OP field, OnInputChange trigger. And something happened. The messages appeared. The problem is, the first one came empty and the second one showed a 0. Am I not using the right variable?
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
      RecRoutingHeader."No." := "No. Macho";
      RecRoutingHeader.Description := Description;
      RecRoutingHeader.INSERT;
    END;
    RecRoutingHeader."No." := "No."; // Modified this line again
    MESSAGE('%1',RecRoutingHeader."No.");
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
      RecRoutingLine."Routing No." := "Routing No.";
      RecRoutingLine.Description := Description;
      RecRoutingLine."Run Time" := "Run Time";
      RecRoutingLine.INSERT;
    END;
    MESSAGE('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    RecRoutingHeader.RESET;
    RecRoutingHeader.SETRANGE("No.","No. Macho");

    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN
    RecRoutingHeader."No." := "No. Macho";
    RecRoutingHeader.Description := Description;
    RecRoutingHeader.INSERT;
    END;

    Message('%1',RecRoutingHeader."No.");

    RecRoutingLine.RESET;
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
    RecRoutingLine"Routing No." := RecRoutingHeader."No.";
    RecRoutingLine.Description := Description;
    RecRoutingLine."Run Time" := "Run Time";
    RecRoutingLine.INSERT;
    END;
    Message('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";
  • sarmigsarmig Member Posts: 89
    RecRoutingHeader.RESET;
    RecRoutingHeader.SETRANGE("No.","No. Macho");

    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN
    RecRoutingHeader."No." := "No. Macho";
    RecRoutingHeader.Description := Description;
    RecRoutingHeader.INSERT;
    END;

    Message('%1',RecRoutingHeader."No.");

    RecRoutingLine.RESET;
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
    RecRoutingLine"Routing No." := RecRoutingHeader."No.";
    RecRoutingLine.Description := Description;
    RecRoutingLine."Run Time" := "Run Time";
    RecRoutingLine.INSERT;
    END;
    Message('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";

    Beautiful!!!! It worked!!!
    What was the difference to the previous code?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Replaced RecRoutingHeader."Routing No." with RecRoutingHeader."No."
  • sarmigsarmig Member Posts: 89
    Anyway, great. Thanks a lot.

    Just one more thing. I need to create a mechanism that, in case Run Time = 0, the form where I can input that data opens automatically.

    From where should I start?
  • sarmigsarmig Member Posts: 89
    I think I got it. Here's the code I came up with:
    RecRoutingHeader.RESET; 
    RecRoutingHeader.SETRANGE("No.","No. Macho");
    
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
     RecRoutingHeader."No." := "No. Macho";
     RecRoutingHeader.Description := Description;
     RecRoutingHeader.INSERT;
    END;
    
    //MESSAGE('%1',RecRoutingHeader."No.");
    
    RecRoutingLine.RESET; 
    RecRoutingLine.SETRANGE("Routing No.",RecRoutingHeader."No."); // // Modified this line again
    IF NOT RecRoutingLine.FINDFIRST THEN BEGIN
     RecRoutingLine."Routing No." := RecRoutingHeader."No.";
     RecRoutingLine.Description := Description;
     RecRoutingLine."Run Time" := "Run Time";
     RecRoutingLine.INSERT;
    END;
    //MESSAGE('%1',RecRoutingLine."Run Time");
    TempoEx := RecRoutingLine."Run Time";
    
    IF RecRoutingLine."Run Time" <= 0 THEN
      IF CONFIRM ('Queres dar um tempo?') THEN
        FORM.RUN(99000766, RecRoutingHeader, RecRoutingHeader."No.");
    

    But now I have another problem. The code works, and as I'm filling the form, the value of Run Time automatically shows up in the TempoExecução field. But then, when I scroll down to the next line, and then back to the first, that value becomes 0. Its like it doesn't store the value. Is there a field property I should change or is it really a code problem?
  • sarmigsarmig Member Posts: 89
    I got it to work. Thanks. Now, for the next problem:

    My RecRoutingHeader table has an option type variable called "Status".

    I need that everytime I add a value to Run Time, The Status variable instantly becomes certified. I tried a few solutions, like:

    RecRoutingHeader.Status := RecRoutingHeader.Status::Certified;
    



    But it doesn't work. Can you help out?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    You want to set Status to certified in My RecRoutingHeader or you want to access that and show in present form?
  • sarmigsarmig Member Posts: 89
    I want to set the status in RecRoutingHeader to Certified...
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    It wont modify in RecRoutingHeader until you use
    RecRoutingHeader.MODIFY;
    
    After your code
  • sarmigsarmig Member Posts: 89
    It wont modify in RecRoutingHeader until you use
    RecRoutingHeader.MODIFY;
    
    After your code

    I have something like this, and it doesn't work:
    IF NOT RecRoutingHeader.FINDFIRST THEN BEGIN 
     RecRoutingHeader."No." := "No. Macho";
     RecRoutingHeader.Description := Description;
     RecRoutingHeader.Status := RecRoutingHeader.Status::Certified;
     RecRoutingHeader.INSERT;
     END ELSE BEGIN
     RecRoutingHeader.Status := RecRoutingHeader.Status::Certified;
     RecRoutingHeader.MODIFY;
    END;
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
Sign In or Register to comment.