Transfer values from one form to another

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…

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…

I do have a value, but the value is wrong, and it’s the same value to every line I’m transfering…

That’s the thing, I don’t know why the filters are not filtering correctly…

RecExtra.SETRANGE(“No. Computador”, RecItem.“No.” + ‘#’);

Does your RecExtra.“No. Computador” contains item.No + #?

Yes.

In the Item table, the No. field is like 123

In the Extra table, the No. Computador field is like 123#

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?

And now I know why. The values didn’t exist. Problem solved!