How to recalculate custom field value every time it is queried

I want to add a jira:customFieldType module to my Forge app. Its value will be a read-only user list, and this list will be dynamically calculated from some derived data (e.g., data from the Storage API). I plan to use the value function for this calculation.

Here is the custom field type definition from the manifest file:

jira:customFieldType:
    - key: custom-field-type-calculated-users
      name: Calculated Users
      type: user
      collection: list
      readOnly: true
      value:
        function: calculateUsers

Currently, the calculateUsers function is only invoked when the issue view is rendered. It is not invoked when I query an issue via the REST API or when the issue search screen is in list mode. I need this custom field value to be recalculated every time it is queried from anywhere.

Is this possible with the current state of Forge? Is there any workaround to achieve this behavior?

Hey @Berkayztrk,

As suggested in the documentation, the read-only fields section:

The value of such fields has to be calculated beforehand and set with the dedicated REST API. One pattern to achieve this is to listen to product triggers for events that may affect the values and update the values as necessary.

More specifically, it’s not possible to directly trigger the computation in response to fields being rendered, apart from the issue view, as you have already noticed.

Hi @kkercz,

Thank you for your response.

In our case, using product triggers won’t work as the custom field needs to be dependent on an external system and its value must be synced with the external system data all the time. As I understand, we can’t do this as of today.

On Jira Server, custom field values can be recalculated every time they are queried. Will the value function of Forge have the same behavior in the future?

Thanks.

In that case you should synchronize the custom field value whenever the value in the external system changes. One way to do it would be for your external system to inform your Forge app about the change using a web trigger.

I’m afraid that right now we don’t have any short-term plans for extending the scope of the value function.