Refresh computed field of backend document

Hi all,

I have two databases say d/b A and d/b B.

Documents of d/b A pulls some values from documents from d/b B. On the form of d/b A, I have 2 fields

  1. ed_field : Editable (and hidden) field which pulls value of some field of document of d/b B

  2. cmp_field : Computed (and visible) field which has default value as value of ed_field.

Now I wanted a scenario wherein, when document of d/b B (say BDoc) changes, the document of d/b A (say ADoc) which are using values from the BDoc should get updated automatically.

To achieve this, code has been written on the querysave event of form of BDoc which performs following functions

  1. Finds out documents of d/b A (ADoc), which are using BDoc.

  2. Updates the field value of ed_field of ADoc

  3. Performs ComputeWithForm on ADoc

  4. Saves ADoc and BDoc

Now as cmp_field is computed field, I was expecting that I will be able to see updated values in cmp_field. But It didn’t happened so. To crosscheck, I unhided the ed_field and check its value, it was having the updated value. It means computed field wasn’t getting refreshed.

Then even I tried to achieve the same by setting the “Automatically Refresh Fields” property of form of d/b A. But even this didn’t work.

Is there any way to achieve this, except directly updating the computed field in the querysave code itself.

Wating for responses.

Thanks in advance :slight_smile:

Harshad

Subject: Refresh computed field of backend document

Hi Harshad,

One way to achieve this would be to have cmp_field as a computed for display field (or even replace it with computed text) if all you want is to display the pulled value to the user. When testing, check it with newly created documents and not with one created when the field was simply computed.

Another way would be to change your code and have it set both the editable and computed field to the pulled value.

A question to ask is, why have the hidden editable field? Are you ever going to want to do anything other than look at the value pulled from the other db? If you don’t need to edit it just have a computed field. Set it to compute to itself and update with your “pull data” code.

HTH

John

Subject: Refresh computed field of backend document

Dear Harshad

Unfortunately the ComputeWithForm method does NOT run computed fields. it does input translation and input validation events.

Automatically refresh fields will not help in this case.

Your options are:

  1. use your code to set cmp_field. This would be the best for performance as computewithform has to run all editable fields. Makes code slower.

e.g. ADoc.cmp_field=Adoc.ed_field

or

  1. Put this in the input translation of ed_field:

FIELD cmp_field=@thisvalue;

@thisvalue

This means that ed_field input translation will update cmp_field value when you call computewithform.