[Not Solved]Change Fields while dataport is running

RokeRoke Member Posts: 7
Hi,
I want to do a dataport that export all records that have one field not cheked, and them when the dataport finish to export check this field. I have that code :

Movimientos tarjetas - OnPostDataItem()
recMovimientos.SETRANGE(recMovimientos.Sincronizado,FALSE);
recMovimientos.FINDFIRST;
REPEAT
recMovimientos.Sincronizado := TRUE;
recMovimientos.MODIFY;
UNTIL (recMovimientos.NEXT = 0);

But it doesnt work, is like the navision dont do a COMMIT, if i put a commit at the end it works. Some sugestions ?
Thanks for all.

Comments

  • BeliasBelias Member Posts: 2,998
    your code doesn't work because you're applying filters on a field you are going to modify...so you are losing the pointer on the record (I don't know if i told well in english)
    substitute your code with this one...recMovimientos2 it's the same rec variable of recMovimientos...

    recMovimientos.SETRANGE(recMovimientos.Sincronizado,FALSE);
    recMovimientos.FINDSET;
    recMovimientos2.RESET;
    REPEAT
    recMovimientos2.get(recMovimientos."primary key");
    recMovimientos2.Sincronizado := TRUE;
    recMovimientos2.MODIFY;

    UNTIL (recMovimientos.NEXT = 0);
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • EugeneEugene Member Posts: 309
    the problem with original code is that once you change the value from FALSE to TRUE you jump down in the records list and skip all records with FALSE VALUE:

    1 FALSE (when changed to TRUE you jump from 1st to 4th record)
    2 FALSE (this one is skipped)
    3 FALSE (this one is skipped)
    4 TRUE

    Alternatively you can try to loop from end to top:
    Movimientos tarjetas - OnPostDataItem()
    recMovimientos.SETRANGE(recMovimientos.Sincronizado,FALSE);
    recMovimientos.FINDLAST;
    REPEAT
    recMovimientos.Sincronizado := TRUE;
    recMovimientos.MODIFY;
    UNTIL (recMovimientos.NEXT(-1) = 0);
    
  • DenSterDenSter Member Posts: 8,305
    No that is not how you do it, in fact that is about the worst you can do. FINDFIRST and FINDLAST are NOT intended to be used when you need to loop through records, that is what FINDSET is for. Second, reverse looping through a record set is also not very safe, and could contribute to deadlocks.

    If you need to modify a field that you filter on, then you have two options:
    1 - you use a second variable to modify the record, just like Belias suggests.

    2 - you use the FINDSET parameter to control its behavior. Go to the C/SIDE reference guide under the Help menu and read about FINDSET.
  • RokeRoke Member Posts: 7
    Thanks for all help but it doesnt work. I do it with FINDSET but doesnt work.
    I see on debug and the value change to false but dont save in database.

    If i put the COMMIT sentence at the end the program works. THe tableview of the dataport its SORTING(No. Tarjeta,Numero Documento Asociado) ORDER(Ascending) WHERE(Sincronizado=CONST(No))

    ](*,) I think its for the type of transaction, but i try with all combinations. More suggestions please.

    Thanks.
  • BeliasBelias Member Posts: 2,998
    edited 2008-03-18
    I've ever used the code I wrote for a lot...try with that solution...otherwise can you post your code?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • RokeRoke Member Posts: 7
    I dont have it :(
    I dont know what i do but i dont have.

    Some suggestions ???

    Here is the code:

    OBJECT Dataport 50000 Exportar Tarjetas MM.AA
    {
    OBJECT-PROPERTIES
    {
    Date=18/03/08;
    Time=14:03:43;
    Modified=Yes;
    Version List=;
    }
    PROPERTIES
    {
    FileFormat=Variable;
    OnPostDataport=BEGIN
    MESSAGE('proceso finalizado correctamente');
    END;

    }
    DATAITEMS
    {
    { PROPERTIES
    {
    DataItemTable=Table50002;
    AutoSave=Yes;
    AutoUpdate=Yes;
    AutoReplace=Yes;
    DataItemTableView=SORTING(No. Tarjeta,Numero Documento Asociado)
    ORDER(Ascending)
    WHERE(Sincronizado=CONST(No));
    OnAfterExportRecord=BEGIN
    recMovimientos.GET("Movimientos tarjetas"."No. Tarjeta","Movimientos tarjetas"."Numero Documento Asociado");
    recMovimientos.Sincronizado := TRUE;
    recMovimientos.MODIFY;
    END;

    }
    FIELDS
    {
    { ; ;"Fecha Registro" }
    { ; ;"No. Tarjeta" }
    { ; ;"Numero Documento Asociado" }
    { ; ;Descripcion }
    { ; ;"Importe Documento" }
    { ; ;"No. Puntos" }
    { ; ;"No. Cliente" }
    { ; ;"Nombre Cliente" }
    { ; ;"Nombre Empresa" }
    { ; ;Sincronizado }
    }
    }
    { PROPERTIES
    {
    DataItemTable=Table50000;
    DataItemTableView=SORTING(No. Tarjeta,Cod. Cliente)
    ORDER(Ascending)
    WHERE(Sincronizado=CONST(No));
    OnAfterExportRecord=BEGIN
    recTarjetas.GET("Tarjeta Cliente"."No. Tarjeta","Tarjeta Cliente"."Cod. Cliente");
    recTarjetas.Sincronizado := TRUE;
    recTarjetas.MODIFY;
    END;

    }
    FIELDS
    {
    { ; ;"No. Tarjeta" }
    { ; ;"Fecha Entrada Vigor" }
    { ; ;"Fecha Caducidad" }
    { ; ;"Cod. Cliente" }
    { ; ;Saldo }
    { ; ;"Nombre de la Empresa" }
    { ; ;Sincronizado }
    { ; ;"No. Series" }
    }
    }
    }
    REQUESTFORM
    {
    PROPERTIES
    {
    Width=9020;
    Height=3410;
    }
    CONTROLS
    {
    }
    }
    CODE
    {
    VAR
    recMovimientos@1000000000 : Record 50002;
    recTarjetas@1000000001 : Record 50000;

    BEGIN
    END.
    }
    }
  • krikikriki Member, Moderator Posts: 9,110
    If you run your dataport directly from the dataport design-mode, you have this effect:the DB-changes are not commited. You need to save your dataport and then run it through the menu or directly from the object designer.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.