Transfer values from one form to another

sarmigsarmig Member Posts: 89
Hello,

I'm faced with another barrier, one that I thought I could break, but I haven't been able to.

Try to follow:

I'm developing a functionality for my company, and it involves two forms (sales line and a custom made form). The goal is to transfer the data from the first form to the second. That I can do. The problem is there is one field in the second form that is not in the first one, and I'm losing my mind trying to filter through tables to get it. Maybe you'll understand better if I post my current code here. This code is in the OnPush trigger of the button I'm using to transfer the fields:
recSalesLine.INIT;
recSalesLine.SETRANGE(recSalesLine.Atribuir, TRUE);
IF NOT recSalesLine.FINDFIRST THEN
  ERROR('Não está qualquer linha seleccionada');

REPEAT
  RecItem.RESET;
  RecItem.SETRANGE("No.", "No.");
  IF RecItem.FINDFIRST THEN BEGIN
    MESSAGE('%1', RecItem."No.");

    RecExtra.RESET;
  //RecExtra.SETRANGE(Tabela, RecExtra.Tabela::LCM);
    RecExtra.SETRANGE("No. Computador", RecItem."No." + '#');
  END;
  

  RecCarp.RESET;
  RecCarp.SETRANGE("Data Registo", TODAY);
  RecCarp.SETRANGE("Sales No.", recSalesLine."Document No.");
  RecCarp.SETRANGE("Sales Line No.", recSalesLine."Line No.");
  RecCarp.SETRANGE("Tipo Operação", "Tipo Operação"::Construção);
  RecCarp.SETRANGE("No.", recSalesLine."No.");
  RecCarp.SETRANGE("No. Equipamento", RecExtra.Code);
  IF RecCarp.FINDFIRST THEN
    ERROR('O Equipamento encontra-se já em fase de produção da Carpintaria.');


  //Rec.INIT;
  RecCarp."Data Registo":= TODAY;
  RecCarp."Sales No." := recSalesLine."Document No.";
  RecCarp."Sales Line No." := recSalesLine."Line No.";
  RecCarp."No.":=recSalesLine."No.";
  RecCarp."No. Molde" := recSalesLine."Nº Molde";
  RecCarp.Quantity:=recSalesLine.Quantity;
  RecCarp."Delivery Date":= recSalesLine."Planned Delivery Date";
  RecCarp.Estado := Estado::Lançar;
  RecCarp."Tipo Operação" := "Tipo Operação"::Construção;
  RecCarp."Sistema Moldação" :=  recSalesLine."Local de Producao";
  IF RecExtra.FINDFIRST THEN
    RecCarp."No. Equipamento" := RecExtra.Code;
  RecCarp.INSERT;
//  MESSAGE('%1', RecCarp."No. Equipamento");
  recSalesLine.Atribuir := FALSE;
  recSalesLine.MODIFY;
//  recSalesLine.NEXT;
UNTIL recSalesLine.NEXT = 0;

If the filters were all correct, the line RecCarp."No. Equipamento" := RecExtra.Code; should get me the value I was searching, but it isn't happening. I'm asking you to help me once again...

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    I didnt check full code but

    are you sure you have value in RecExtra.Code?

    Put a message after
    IF RecExtra.FINDFIRST THEN
    Message('%1',RecExtra.Code);

    to check whether you got right record or not..
    if not check where you are filtering RecExtra..
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    sarmig wrote:
    RecExtra.SETRANGE("No. Computador", RecItem."No." + '#');

    What does it do?
    I never used this kind of code :-k
  • sarmigsarmig Member Posts: 89
    It adds a '#' to the end of a ref. so that it can be found in that table. the ref.+# represents unfinished products in my company...
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    If you know how to use Debugger..check the values at run time

    or simply put messages and check where the value is missing..
  • sarmigsarmig Member Posts: 89
    I tried to use the debugger, but the problem is that, in this case, the debugger is not very usable, since every time I try to transfer the values, it runs code in the sales line table (OnModify trigger) and it takes forever to reach the part of the code I want...
  • sarmigsarmig Member Posts: 89
    I rearranged the code a little bit. Found another way to the values I need without going through the "Extra" table.
    recSalesLine.INIT;
    recSalesLine.SETRANGE(recSalesLine.Atribuir, TRUE);
    IF NOT recSalesLine.FINDFIRST THEN
      ERROR('Não está qualquer linha seleccionada');
    
    REPEAT
      RecItem.RESET;
      RecItem.SETRANGE("No.", recSalesLine."No." + '#');
      IF RecItem.FINDFIRST THEN BEGIN
      RecCarp.RESET;
      RecCarp.SETRANGE("Data Registo", TODAY);
      RecCarp.SETRANGE("Sales No.", recSalesLine."Document No.");
      RecCarp.SETRANGE("Sales Line No.", recSalesLine."Line No.");
      RecCarp.SETRANGE("Tipo Operação", "Tipo Operação"::Construção);
      RecCarp.SETRANGE("No.", recSalesLine."No.");
      RecCarp.SETRANGE("No. Equipamento", RecItem."Cod Equip");
      IF RecCarp.FINDFIRST THEN
          ERROR('O Equipamento encontra-se já em fase de produção da Carpintaria.');
    
    
     // Rec.INIT;
      RecCarp."Data Registo":= TODAY;
      RecCarp."Sales No." := recSalesLine."Document No.";
      RecCarp."Sales Line No." := recSalesLine."Line No.";
      RecCarp."No.":=recSalesLine."No.";
      RecCarp."No. Molde" := recSalesLine."Nº Molde";
      RecCarp.Quantity:=recSalesLine.Quantity;
      RecCarp."Delivery Date":= recSalesLine."Planned Delivery Date";
      RecCarp.Estado := Estado::Lançar;
      RecCarp."Tipo Operação" := "Tipo Operação"::Construção;
      RecCarp."Sistema Moldação" :=  recSalesLine."Local de Producao";
      RecCarp."No. Equipamento" := RecItem."Cod Equip";
      RecCarp.INSERT;
      MESSAGE('%1', RecCarp."No. Equipamento");
      recSalesLine.Atribuir := FALSE;
      recSalesLine.MODIFY;
      END;
    UNTIL recSalesLine.NEXT = 0;
    

    The thing is, I tried to transfer 7 lines, and only the first 2 had the "No. Equipamento", the rest were empty. What am I missing?
  • sarmigsarmig Member Posts: 89
    And now I know why...The values didn't exist. This problem's solved!
Sign In or Register to comment.