Copy a field to another field on the same table

DarkHorseDarkHorse Member Posts: 389
Hello, need put a flowfield field (field1) from a table as a key, but Navision doesn't let it. Then I think create a new field (field2) and copy the content from field1 to field2 and put field2 as a key, but there is no way. I put in OnValitade from field1 the following code:

table.CALCFIELDS(field1);
field2:=field1;

How can I do this?.
Thanks.

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi,

    You should perhaps do this in the OnModify trigger


    Albert
  • BeliasBelias Member Posts: 2,998
    Onvalidate trigger fires when the field is validated, CALCFIELDS does not validate the field.
    the update of the field2 can be painful, as you have to maintain it also when a flowfield changes value...
    you can update your field2 in onaftergetrecord trigger of a form, but before doing calculations, check if field2 is really <> from field1 to minimize performance issues
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • garakgarak Member Posts: 3,263
    The flowfield calculate his value during runtime. So you can't copy the value to the field2.
    Only on a Form but this is ](*,) ](*,)

    So, whats the reason why you need the field as keyfield?
    Do you make it right, it works too!
  • BeliasBelias Member Posts: 2,998
    anyway, you can use my method, but you are not sure that data is 100% updated, because if you use the new key somewhere else, the form is not run and the fields are not updated (you can for sure create a function in the form to calculate the fields and after use setcurrentkey, but it's not good at all [-X )
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • DarkHorseDarkHorse Member Posts: 389
    Thank you all. In a form works perfectly!!, but by this way I can't make this field a key. Well, thanks again for reply.
  • matttraxmatttrax Member Posts: 2,309
    You don't have to just update the field on a timer or at random intervals.

    Take the table that contains the field you want to sum (or do whatever with). When this table is modified update the value in the table that has the new key field in it.

    You'll have to do a bulk load first to fill in the field for existing records. And you'll also have to be sure that the modify/insert trigger [MODIFY(TRUE)] is called instead of just MODIFY/INSERT.

    Weigh your performance hit, which shouldn't be much, against how badly you need to sort on the column.
Sign In or Register to comment.