Copy a field content to a nother field on same table

Mic28Mic28 Member Posts: 13
Hello everybody; I've created a decimal field in a table and simply I want to copy the content of another decimal field from the same table. I've try newfield:=oldfiel; but doesn't works. I suppose it's easy but I'm starting with C/AL and I don't know too much.
Thanks.

Comments

  • philippegirodphilippegirod Member Posts: 191
    Copy from the same table ? This means also from the same record ?
    In any case, if you are doing this operation thrue a report, don't forget the MODIFY instruction.
    For instance:
    Table1.Field2 := Table1.Field1;
    Table1.MODIFY;
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • Mic28Mic28 Member Posts: 13
    Thanks; yes, in the same table the same, copy the contenct of that field. This code that you've posted; I have to put in OnValidate from fileld1 from table or where, please?.
    Thank you for help.
  • philippegirodphilippegirod Member Posts: 191
    No, the modify is only necessary for Report and Dataport.
    In the Table, in the field containing the data to be copied ("Field 1" in our example), your code must be in OnValidate :
    "Field 2" := "Field 1";

    Be carefull to the key:if "Field 2" is in the primary key you'll have to rename the record
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • Mic28Mic28 Member Posts: 13
    Thanks for reply, but it doesn't work; this is how I've commented that I had done in my first post; I've put field2:=field1; in OnValidate from field1 (also on field2) but it shows 0. Any idea please?.
    Thanks.
  • philippegirodphilippegirod Member Posts: 191
    Why it could not work:
    1. Because you are on a form, so your value is not updated
    2. Because the field is not editable
    3. Because the destination field is in primary key
    4.....

    So:

    Your code must be in the table and not in the form
    If you modification is made in the form (when your code is really in the table) you must update your form to see the change.
    Check if Field 2 is editable (in the table)
    Check if it's not a flow field
    Check if it's not a part of the primary key
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • Mic28Mic28 Member Posts: 13
    Thanks for reply; all it's ok, I'm doing it in table, except that field1 it's a flowfield; any problem with this?.
    Thanks.
Sign In or Register to comment.